HomebaseWorks

SQL query-writing questions

Questions where you write the query aloud or on a whiteboard, with model answers.

EWritten by the HomebaseWorks editorial team · reviewed 26 Oct 2026
1
Customers who have never placed an order.

SELECT c.* FROM customers c LEFT JOIN orders o ON o.customer_id = c.id WHERE o.id IS NULL;

2
Total sales per month for this year.

SELECT DATE_FORMAT(created_at, '%Y-%m') AS month, SUM(total) FROM orders WHERE YEAR(created_at) = YEAR(CURDATE()) GROUP BY month ORDER BY month; (function names vary by database).

3
The second-highest salary.

SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees); or use DENSE_RANK() in databases that support window functions.

Advertisement
4
Delete orders older than a year, safely.

First: SELECT COUNT(*) FROM orders WHERE created_at < DATE_SUB(CURDATE(), INTERVAL 1 YEAR); check the count; then run DELETE with the same WHERE inside a transaction.

5
Top 3 customers by spend.

SELECT c.name, SUM(o.total) AS spent FROM customers c JOIN orders o ON o.customer_id = c.id GROUP BY c.name ORDER BY spent DESC LIMIT 3;

6
Count of orders by status, including statuses with zero.

Start from a statuses table (or a VALUES list) and LEFT JOIN orders, then GROUP BY status and COUNT(o.id). COUNT(*) would wrongly count the empty join as 1.

Practise out loud. Say each answer once as written, then again in your own words with your own number or story.

Have a number ready. "My SQL score is at benchmark on a timed test" is a stronger answer than "I am good at it". Take the test and quote the result.

Advertisement
Continue with SQL4 lessons · 2 interview sets · 1 test · 1 certificate
Not tested

More in Accounts and data