SQL Topic
SQL JOINs
JOINs combine rows from two tables on a relationship. INNER JOIN keeps only matches, LEFT JOIN keeps all left rows and fills unmatched with NULL, and a self join joins a table to itself. Anti-joins (NOT EXISTS / LEFT JOIN ... IS NULL) find rows with no match.
When is SQL JOINs used?
Almost every real question: relating orders to customers, employees to managers, visits to transactions, or comparing rows within one table.
Core syntax
SELECT ... FROM a INNER JOIN b ON a.key = b.key; LEFT JOIN b ON ... WHERE b.key IS NULL is the classic anti-join.Common mistakes
- Using INNER JOIN when the question implies LEFT JOIN (e.g. 'including those with none').
- Forgetting the join condition, producing a cartesian product.
- Double-counting rows when the joined side has duplicates.
- Filtering on the right table in WHERE, which silently converts a LEFT JOIN into an INNER JOIN.
Practice SQL JOINs questions
Work through them in order — each question builds on the last.