InterviewStack.io LogoInterviewStack.io

SQL Query Fundamentals Questions

Core SQL for reading and shaping data: SELECT, filtering with WHERE, sorting, DISTINCT, and single-table aggregation with GROUP BY, HAVING, and aggregate functions. Covers reasoning about NULL handling, grouping semantics, and writing correct queries against a given schema. The baseline query-writing surface most data and engineering interviews open with.

EasyTechnical
56 practiced

Given orders(order_id, customer_id, order_date, total_amount), write a query returning for each customer: first_order_date, last_order_date, total_orders, and lifetime_value (SUM of total_amount). Why are MIN/MAX useful for customer lifecycle reporting?

MediumTechnical
44 practiced

Given customers(id), orders(order_id, customer_id), and order_items(order_item_id, order_id, product_id, qty, unit_price), compute total revenue per customer. Explain why joining customers directly to order_items and then grouping can silently double-count revenue, and show the safe pattern: pre-aggregate order_items to order totals first, then join up to customers.

EasyTechnical
55 practiced

Describe the practical differences between DELETE, TRUNCATE, and DROP. Cover transactional behavior and rollback, performance, permission requirements, and whether triggers fire for each.

EasyTechnical
48 practiced

Given order_items(order_item_id, order_id, product_id, price, quantity), write a query returning the top 5 products by total revenue, using ORDER BY and LIMIT. Show how to make tie-breaking deterministic with a secondary sort column.

MediumTechnical
45 practiced

Given customers, orders, and order_items, write a query returning each customer's distinct product count using COUNT(DISTINCT product_id) across a join chain. Explain why a plain COUNT(*) or COUNT(order_item_id) after joining through orders can overcount compared to COUNT(DISTINCT), and how NULLs from an outer join affect each form.

Unlock Full Question Bank

Get access to all SQL Query Fundamentals interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.