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.

HardTechnical
39 practiced

Explain how implicit type casting and precision differences can affect GROUP BY behavior (e.g., grouping numeric-looking strings versus numeric types, or floating-point imprecision producing unexpected extra groups). What practical steps standardize group keys and avoid miscounts?

MediumTechnical
42 practiced

Using ROLLUP(category, subcategory) on sales(category, subcategory, amount), write a query returning category, subcategory, total_amount, and a label distinguishing detail rows from subtotal and grand-total rows. Explain how GROUPING() or GROUPING_ID helps identify which rows are totals.

HardTechnical
83 practiced

Given orders(order_id, vendor_id, amount, status) and vendors(vendor_id, name), compute average order value per vendor, but only for completed orders and only for vendors with at least 100 such orders. Write the query, applying the status filter with WHERE (before aggregation) and the count threshold with HAVING (after aggregation), and explain why each belongs where it does.

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.

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.