SQL Joins Explained
Combining rows from two or more tables â the most-used SQL skill.
INNER JOIN
Returns only rows that have matching values in both tables. If a row in Table A has no match in Table B, it's excluded from the result.
SELECT s.name, c.course_name
FROM students s
INNER JOIN courses c ON s.course_id = c.id;LEFT JOIN
Returns all rows from the left table, plus matched rows from the right table. Unmatched right-side columns show as NULL â useful when you want to keep every record from your main table.
RIGHT JOIN & FULL JOIN
RIGHT JOIN mirrors LEFT JOIN but keeps all rows from the right table instead. FULL JOIN keeps all rows from both tables, matching where possible and filling NULLs where there's no match.
đ Real-World Use
An admin dashboard showing 'all students and their enrolled courses, including students with no course yet' uses a LEFT JOIN â this is one of the most common real-world join patterns you'll write on the job.
đĄ Pro Tip
Draw a Venn diagram mentally (or on paper during an interview) for each join type â it's the fastest way to explain and remember exactly which rows get included or excluded.
đ§Ē Quick Self-Test
Check what you just learned â no pressure, just practice.
1. Which join returns only matching rows from both tables?
2. In a LEFT JOIN, what happens to unmatched right-table columns?