Skip to content
Interview Pages

10 SQL Queries That Run but Give the Wrong Answer

A free PDF for anyone preparing for SQL interview questions. No error message will warn you about these. The query runs and the answer is wrong.

Tested on MySQL 8.4 (default settings), with the real output of every wrong and fixed query

All ten traps use one small database, with a setup script so you can create it and run every query yourself.

Free. No payment details needed.

Interview Pages Editorial
Written by a computer-science educator with a PhD and industry software experience

Get the free PDF by email

Sign-up opens soon. This form isn't active yet, so nothing you type here is sent anywhere.

When it opens, we'll use your email only to send the PDF and occasional Interview Pages updates. Unsubscribe any time. See our privacy policy.

Each trap covers

What's inside

  1. NOT IN with a NULL in the subquery
  2. = NULL instead of IS NULL
  3. LEFT JOIN, then filtering the right table in WHERE
  4. COUNT(*) after a LEFT JOIN
  5. Second-highest salary with LIMIT/OFFSET and a tie
  6. Filtering rows (WHERE) when you meant to filter groups (HAVING)
  7. A join that repeats rows and inflates SUM
  8. BETWEEN on a DATETIME column
  9. AVG silently skips NULLs
  10. Case- and accent-insensitive comparison under the default collation

Read the NOT IN trap in full