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.
Given products(product_id, name) and orders(order_id, product_id), write two queries finding products that have never been ordered: one using NOT EXISTS (or NOT IN), one using LEFT JOIN with WHERE orders.product_id IS NULL. When would you prefer one over the other?
Discuss the trade-offs of referring to GROUP BY columns by ordinal position (GROUP BY 1, 2) versus repeating the full expression versus using a CTE/alias. When is each acceptable in production SQL?
Given transactions(transaction_id, user_id, amount DECIMAL(9,2), occurred_at), write a query returning transactions with amount between $50 and $500 inclusive. Show the equivalent query using explicit >= and <= instead of BETWEEN, and state whether BETWEEN is inclusive on both ends.
Using De Morgan's laws, rewrite NOT (status = 'shipped' OR status = 'delivered') into an equivalent WHERE clause that has no top-level NOT. Why can rewriting boolean expressions like this help readability and the optimizer?
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.