
SQL Joins Made Easy | INNER, LEFT, RIGHT, FULL Joins with Examples
In relational databases, data is often split across multiple tables for better structure. But to get the full picture, you need to combine that data — and that’s where SQL Joins come in.
In this episode, you’ll learn:
- The four main types of SQL joins
- When to use each one
- Real-world examples using simple tables
Let’s get started!
What Is a SQL Join?
A SQL Join is used to combine rows from two or more tables based on a related column between them.
Why use joins?
To query and analyze related data that lives in different tables.
Sample Tables
We’ll use two simple tables: students and enrollments.
Table: students
student_id | name |
1 | Zara |
2 | Ali |
3 | Ayesha |
Table: enrollments
enrollment_id | student_id | subject |
101 | 1 | Math |
102 | 2 | English |
103 | 4 | Physics |
1. INNER JOIN – Matching Data from Both Tables
Returns only the rows with matching student IDs in both tables.
SELECT students.name, enrollments.subject
FROM students
INNER JOIN enrollments
ON students.student_id = enrollments.student_id;
Result:
name | subject |
Zara | Math |
Ali | English |
Student ID 4 from enrollments is not shown because it doesn’t exist in the students table.
2. LEFT JOIN – All from Left Table + Matches from Right
Returns all students, and their subject if available.
SELECT students.name, enrollments.subject
FROM students
LEFT JOIN enrollments
ON students.student_id = enrollments.student_id;
Result:
name | subject |
Zara | Math |
Ali | English |
Ayesha | NULL |
Ayesha has no enrollment, so subject is NULL.
3. RIGHT JOIN – All from Right Table + Matches from Left
Returns all enrollments, even if the student doesn’t exist.
SELECT students.name, enrollments.subject
FROM students
RIGHT JOIN enrollments
ON students.student_id = enrollments.student_id;
Result:
name | subject |
Zara | Math |
Ali | English |
NULL | Physics |
Enrollment with student ID 4 has no match in students, so name is NULL.
4. FULL JOIN – Everything from Both Tables
Combines LEFT and RIGHT JOIN: shows all records, even if unmatched.
SELECT students.name, enrollments.subject
FROM students
FULL JOIN enrollments
ON students.student_id = enrollments.student_id;
Result:
name | subject |
Zara | Math |
Ali | English |
Ayesha | NULL |
NULL | Physics |
Note: FULL JOIN is not supported in MySQL by default, but you can simulate it using UNION.
Summary of SQL Joins
Join Type | Description | Shows unmatched data from |
INNER JOIN | Only matching rows in both tables | |
LEFT JOIN | All rows from left + matches from right | Left table |
RIGHT JOIN | All rows from right + matches from left | Right table |
FULL JOIN | All rows from both tables | Both tables |
Related Episodes:
- Episode 6: Primary Key vs Foreign Key
- Episode 7: How to Design a Database