🔗 JOINs in SQL
Last Updated: January 2026
JOINs are used to combine data from two or more tables based on a related column (usually a Primary Key ↔ Foreign Key relationship).
Real databases store data in separate tables to avoid duplication.
Example:
students→ student infoenrollments→ course info
To see student name + course, we must JOIN tables.
Hinglish Tip 🗣: Jab data alag-alag tables me ho aur ek hi result me chahiye →
JOINlagta hai.
Basic JOIN Syntax
SELECT columns
FROM table1
JOIN table2
ON table1.common_column = table2.common_column;
🔑 Types of JOINs
We’ll cover each JOIN in detail in separate tutorials. Here is the overview only.
INNER JOIN
- Returns only matching rows from both tables
FROM A
INNER JOIN B
ON A.id = B.id
LEFT JOIN (LEFT OUTER JOIN)
- All rows from left table
- Matching rows from right table
- Non-matching →
NULL
FROM A
LEFT JOIN B
ON A.id = B.id
RIGHT JOIN (RIGHT OUTER JOIN)
- All rows from right table
- Matching rows from left table
FROM A
RIGHT JOIN B
ON A.id = B.id
FULL JOIN (FULL OUTER JOIN)
- All rows from both tables
- Non-matches filled with
NULL
FROM A
FULL JOIN B
ON A.id = B.id
CROSS JOIN
- Every row of table A × every row of table B
- No condition required
FROM A
CROSS JOIN B
⚠️ Use carefully — result size grows fast.
🔄 Logical SQL Execution Order (With JOIN)
Understanding this avoids confusion later:
- FROM
- JOIN (ON condition)
- WHERE
- GROUP BY
- HAVING
- SELECT
- ORDER BY
- LIMIT
👉 JOIN happens before filtering and grouping.