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.

MediumTechnical
44 practiced

When grouping by a dimension such as customer_segment that may contain NULLs, SQL groups all the NULLs together. Show how to COALESCE NULLs to 'Unknown' for a dashboard, how to still analyze the NULL group separately when needed, and what it means for joining the result back to a segment dimension table.

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.

MediumTechnical
53 practiced

Given campaigns(id, name, daily_budget) and spends(id, campaign_id, amount, occurred_at), write a query finding campaigns whose total spend on a given date exceeded their daily budget, returning campaign id, name, daily_spend, and daily_budget.

EasyTechnical
39 practiced

Given users(user_id, name, email) and orders(order_id, user_id, total_amount, order_date), write a query listing name, email, order_id, and total_amount for orders over $100, including only users who have at least one such order.

MediumTechnical
40 practiced

Given orders(order_id, created_at TIMESTAMP), explain why filtering March 2024 with created_at BETWEEN '2024-03-01' AND '2024-03-31' can miss rows, since created_at includes a time-of-day. Write a correct, index-friendly query using a half-open range instead.

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.