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.
Can a SELECT alias be used in GROUP BY or ORDER BY? Explain how this differs across PostgreSQL, MySQL, and SQL Server, and give a portable recommendation for writing SQL that needs to run on more than one engine.
Given users(email), write a query grouping by a computed expression (the substring after '@', case-insensitively) to count users per email domain. How would you speed this grouping up with a functional index in PostgreSQL, and how would you exclude malformed rows with no '@'?
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.
SELECT category, product_name FROM sales GROUP BY category; raises an error about a non-aggregated column. Explain why, and give two different corrections depending on business intent: picking one representative product per category, versus listing every category/product pair.
Given products(product_id, name, category), write a query returning rows where category is one of 'electronics', 'appliances', or 'furniture'. Show it two ways: using IN and using chained OR comparisons. Which is clearer, and does it matter for performance?
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.