SQL Advanced Quiz
Window functions, join semantics, NULL behaviour and query plans — the SQL that actually separates candidates in a data or backend interview.
Start the quizSample questions from this quiz
A preview of the style and depth. Try each one, then reveal the answer — or skip straight to the timed quiz.
1. The employees table has 5 rows, 2 of which have a NULL manager_id. What does this return?
SELECT COUNT(*), COUNT(manager_id)
FROM employees;- 3, 3
- 5, 5
- 5, 3
- 5, NULL
Show answer
Answer: 5, 3. COUNT(*) counts rows; COUNT(column) counts non-NULL values in that column. This is the cleanest demonstration that aggregate functions skip NULLs — the same applies to SUM, AVG and MAX, which is why AVG can differ from SUM/COUNT(*).
2. orders has 10 rows; 3 have customer_id values not present in customers. What does this return?
SELECT COUNT(*)
FROM orders o
LEFT JOIN customers c ON o.customer_id = c.id
WHERE c.id IS NULL;- 3
- 10
- 7
- 0
Show answer
Answer: 3. A LEFT JOIN keeps every order and fills NULLs where no customer matched, so filtering on `c.id IS NULL` isolates exactly the orphans. This anti-join pattern is the standard way to find rows missing a counterpart.
3. This is meant to list orders with their customer, including orders with no customer. It silently behaves like an INNER JOIN. Which line breaks it?
1 SELECT o.id, c.name
2 FROM orders o
3 LEFT JOIN customers c ON o.customer_id = c.id
4 WHERE c.country = 'EG';- Line 2 — orders should be the right-hand table
- Line 3 — the join condition should use LEFT OUTER JOIN explicitly
- Line 1 — c.name must be wrapped in COALESCE
- Line 4 — filtering the right table in WHERE discards the NULL-padded rows
Show answer
Answer: Line 4 — filtering the right table in WHERE discards the NULL-padded rows. Unmatched rows get NULL for every right-table column, and `NULL = 'EG'` is UNKNOWN, so WHERE drops them — turning the outer join into an inner one. Move the predicate into the ON clause, which filters before padding rather than after.
Frequently asked questions
How many questions are in this SQL quiz?+
30 questions, with a 45-minute time limit. Every question includes a written explanation of the correct answer.
Is this SQL quiz free?+
Yes. Every quiz on CodexQuizz is free and needs no account. You only enter a name if you choose to post your score to the leaderboard.
What level is the advanced quiz aimed at?+
Window functions, join semantics, NULL behaviour and query plans — the SQL that actually separates candidates in a data or backend interview.
Can I use this to prepare for a SQL interview?+
Yes. The questions cover the topics that come up in SQL technical screens, and the explanations are written so that a wrong answer still teaches you the underlying concept.
Ready to test your SQL?
30 questions, 45 minutes. Free, no sign-up.
Start now