Free preview lesson from SQL for Analysts.
JOINs are where most SQL mistakes in analysis happen. A join that silently drops rows or duplicates them can make a report wrong without any error message.
The two joins you will use most
- INNER JOIN keeps only rows with a match in both tables.
- LEFT JOIN keeps every row from the left table, with NULLs where there is no match.
SELECT c.customer_id, c.name, o.order_id FROM customers c LEFT JOIN orders o ON o.customer_id = c.customer_id;
Check your row counts
Before and after every join, count rows. If the count grows unexpectedly, the join key is not unique on one side, and rows are being duplicated. If it shrinks with an INNER JOIN, some rows had no match.
Exercise
Join two tables you work with. Count rows before and after, then find any key values that appear more than once in the table you expected to be unique using GROUP BY key HAVING COUNT(*) > 1.
Want the rest of the course? See the full SQL for Analysts course page.
Educational content only. No income or earnings results are promised, and no certification, licence or credential is awarded.