Interview SQL tests JOINs, aggregates, NULL logic, indexing intuition, and transaction basics—not obscure vendor trivia. Explain your reasoning aloud while writing queries.
Classic patterns
-- Second highest salary (sketch)
SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
-- Duplicate emails
SELECT email, COUNT(*) AS c
FROM users
GROUP BY email
HAVING COUNT(*) > 1;Practice: Solve on paper, then verify in SQLite.
Topics to rehearse
- INNER vs LEFT JOIN and orphan detection
- WHERE vs HAVING; GROUP BY rules
- NULL comparisons and COALESCE
- Indexes and EXPLAIN at a high level
- Normalization and when to denormalize
- SQL injection and parameterized queries
Communication tips
Clarify schema assumptions, start with simple SELECT, add filters, then optimize. Mention trade-offs (index write cost, pagination OFFSET vs keyset). Pair verbal SQL skills with app knowledge from Python or PHP tracks.
Important interview questions and answers
- Q: Find duplicates interview?
A: GROUP BY key HAVING COUNT(*) > 1. - Q: Index trade-off?
A: Faster reads, slower writes and extra storage—index selective query columns.
Self-check
- How find rows with duplicate email?
- Explain LEFT JOIN + IS NULL pattern in one sentence.
Tip: Talk through JOIN type choice aloud—communication matters as much as syntax.
Interview prep
- Duplicate detection?
GROUP BY key HAVING COUNT(*) > 1.
- LEFT JOIN orphan pattern?
Keep all left rows, filter where right key IS NULL.