SQL JOINs โ Complete Guide
Master all 4 JOIN types with Venn diagrams, real code examples and the anti-join trick. JOINs appear in 89% of data analyst interviews โ this is essential reading.
INNER JOIN โ Only Matching Rows
INNER JOIN returns only rows that have matching values in BOTH tables. If a row in either table has no match, it is excluded from results.
LEFT JOIN โ All Left Rows + Matching Right
LEFT JOIN returns ALL rows from the left table. For rows with no match in the right table, the right columns are filled with NULL. This is the most commonly used JOIN in analytics.
Anti-JOIN โ Find Records That DON’T Match
The anti-join pattern (LEFT JOIN + WHERE IS NULL) finds rows in the left table that have NO match in the right table. This is one of the most commonly asked interview patterns.
SELF JOIN โ A Table Joined to Itself
Practice Questions โ JOINs
FROM customers c
INNER JOIN orders o ON c.id = o.customer_id
WHERE c.city = ‘Bengaluru’;
FROM customers c
LEFT JOIN orders o ON c.id = o.customer_id
WHERE o.order_id IS NULL;
c.customer_name,
COUNT(o.order_id) AS total_orders,
COALESCE(SUM(o.order_amount), 0) AS total_revenue,
MAX(o.order_date) AS last_order_date
FROM customers c
LEFT JOIN orders o ON c.id = o.customer_id
GROUP BY c.customer_name;
Struggling with JOINs?
Book a free mock session. We’ll walk you through JOIN questions from Flipkart, Amazon and more.
Book Free Session