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.
A colleague runs SELECT * FROM hires WHERE hire_date = '2024-03-10'; against a TIMESTAMP column holding values like '2024-03-10 09:15:00' and gets no rows. Explain why, and give two correct ways to find all hires on 2024-03-10.
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.
Explain ROLLUP and CUBE for multi-level aggregation. Using sales(date, region, product, amount), write a single query that produces subtotals by date, by region, and an overall grand total, and explain what the NULLs in the grouping columns of the result mean.
Given orders(order_id, coupon_code VARCHAR, amount) where many rows have coupon_code NULL, write a query showing discount usage counts grouped by coupon_code, labeling NULLs as 'NO_COUPON' via COALESCE. Explain how GROUP BY treats NULL values by default.
A user reports that SELECT * FROM orders WHERE customer_id = 12345; returns no rows, but you know customer_id 12345 exists. List at least four distinct reasons this can happen and the SQL checks you would run to diagnose each.
Unlock Full Question Bank
Get access to all SQL Query Fundamentals interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.