InterviewStack.io LogoInterviewStack.io

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

Given order_items(order_item_id, order_id, product_id, price, quantity), write a query returning the top 5 products by total revenue, using ORDER BY and LIMIT. Show how to make tie-breaking deterministic with a secondary sort column.

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

EasyTechnical
55 practiced

Describe the practical differences between DELETE, TRUNCATE, and DROP. Cover transactional behavior and rollback, performance, permission requirements, and whether triggers fire for each.

EasyTechnical
52 practiced

Given transactions(transaction_id, user_id, amount, transaction_ts), write a query computing total_sales (SUM), average_amount (AVG), and order_count (COUNT) per month for the last 6 months, ordered newest to oldest, omitting months with zero activity.

EasyTechnical
52 practiced

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?

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.