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.

MediumTechnical
53 practiced

Given campaigns(id, name, daily_budget) and spends(id, campaign_id, amount, occurred_at), write a query finding campaigns whose total spend on a given date exceeded their daily budget, returning campaign id, name, daily_spend, and daily_budget.

EasyTechnical
38 practiced

What is the difference between GROUP BY and DISTINCT? Give one example where either works, and one example where GROUP BY with an aggregate is necessary because DISTINCT alone is insufficient.

MediumTechnical
53 practiced

Given orders(order_id, customer_id, order_date, total_amount), write a query finding duplicate orders based on the combination of (customer_id, order_date, total_amount), returning one representative order_id per duplicate group and the duplicate_count. Show the GROUP BY/HAVING approach, and mention how a window function offers an alternative.

MediumTechnical
56 practiced

Given transactions(transaction_id, user_id, amount, occurred_at), write a query returning, per user, the total, average, minimum, maximum, and count of transaction amounts over the last 90 days, including only users with at least 3 transactions in the period, ordered by total descending.

EasyTechnical
40 practiced

Given contacts(contact_id, email, phone), write a query finding rows where phone or email IS NULL, and a separate query for rows where they are empty strings (''). Explain why NULL and '' are different values in SQL and why IS NULL (not = NULL) is required to test for the former.

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.