🔗 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 info
  • enrollments → 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 → JOIN lagta 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:

  1. FROM
  2. JOIN (ON condition)
  3. WHERE
  4. GROUP BY
  5. HAVING
  6. SELECT
  7. ORDER BY
  8. LIMIT

👉 JOIN happens before filtering and grouping.