sql

🔷 SQL: JOINs Refresher

INNER JOIN — only matching rows from both tables survive. LEFT JOIN — ALL left table rows survive. Non-matching right columns become NULL. FULL OUTER JOIN — all rows from both sides. NULLs fill gaps. CROSS JOIN — every row × every row (cartesian product). Usually accidental.

The anti-join pattern (find things with NO match):

SELECT c.customer_id
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
WHERE o.order_id IS NULL;  -- Customers who never ordered

Practice Questions

Q: You INNER JOIN a table of 100 customers with a table of 80 orders. Can you get more than 100 rows?