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
71 practiced

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.

MediumTechnical
50 practiced

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 '@'?

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.

MediumTechnical
40 practiced

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.

EasyTechnical
40 practiced

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 Continue

Join thousands of developers preparing for their dream job.