All SQL quizzes
Intermediate30 questions40 minutes

SQL Intermediate Quiz

Joins, aggregation, subqueries and the NULL behaviour that quietly changes your results — read from real queries rather than definitions.

Start the quiz

Sample 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. customers has 4 rows; only 3 of them have any orders. What does this return?

SELECT COUNT(*)
FROM customers c
JOIN orders o ON o.customer_id = c.id;
  • 1
  • 4
  • 3
  • The total number of orders, not 4
Show answer

Answer: The total number of orders, not 4. An inner join emits one row per matching pair, so the count is the number of orders — not customers. Counting customers needs `COUNT(DISTINCT c.id)`. Confusing these two is the most common cause of inflated numbers in reports.

2. This should show departments with more than 5 employees. It errors. Which line is wrong?

1  SELECT department, COUNT(*) AS n
2  FROM employees
3  WHERE COUNT(*) > 5
4  GROUP BY department;
  • Line 1 — the alias n must be quoted
  • Line 3 — aggregates cannot appear in WHERE; use HAVING after GROUP BY
  • Line 4 — GROUP BY must come before WHERE
  • Line 2 — employees needs an alias
Show answer

Answer: Line 3 — aggregates cannot appear in WHERE; use HAVING after GROUP BY. WHERE is evaluated before rows are grouped, so no aggregate exists yet. HAVING runs after grouping and is where aggregate conditions belong. The rule follows directly from the clause evaluation order: FROM → WHERE → GROUP BY → HAVING → SELECT.

3. The bonus column is NULL for some employees. What does this return for those rows?

SELECT salary + bonus AS total FROM employees;
  • NULL
  • The salary unchanged
  • 0
  • An error
Show answer

Answer: NULL. NULL propagates through arithmetic — anything plus NULL is NULL. Use `salary + COALESCE(bonus, 0)` to treat a missing bonus as zero. This silently zeroes out totals in payroll and reporting queries.

Frequently asked questions

How many questions are in this SQL quiz?+

30 questions, with a 40-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 intermediate quiz aimed at?+

Joins, aggregation, subqueries and the NULL behaviour that quietly changes your results — read from real queries rather than definitions.

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, 40 minutes. Free, no sign-up.

Start now