๐ SQL JOINS are used to combine data from multiple tables.
๐น 1. Why JOINS are Needed?
In real databases, data is stored in different tables.
Example:
Employees Table
emp_id: 1
name: Rahul
Salary Table
emp_id: 1
salary: 50000
๐ To combine employee name with salary โ use JOIN.
๐ฅ 2. INNER JOIN โญ
Returns only matching rows from both tables.
SELECT employees.name, salary.salary
FROM employees
INNER JOIN salary
ON employees.emp_id = salary.emp_id;
โ Most commonly used JOIN.
๐น 3. LEFT JOIN
Returns:
โ All rows from left table
โ Matching rows from right table
SELECT *
FROM employees
LEFT JOIN salary
ON employees.emp_id = salary.emp_id;
๐ Non-matching rows return NULL.
๐น 4. RIGHT JOIN
Returns:
โ All rows from right table
โ Matching rows from left table
SELECT *
FROM employees
RIGHT JOIN salary
ON employees.emp_id = salary.emp_id;
๐น 5. FULL JOIN
Returns all rows from both tables.
SELECT *
FROM employees
FULL OUTER JOIN salary
ON employees.emp_id = salary.emp_id;
๐น 6. SELF JOIN โญ
Joining a table with itself.
Used for:
โ Employee-manager relationships
๐น 7. Visual Understanding
โข INNER JOIN โ Matching only
โข LEFT JOIN โ All left + matching right
โข RIGHT JOIN โ All right + matching left
โข FULL JOIN โ Everything
๐น 8. Why JOINS are Important?
โ Used daily in real projects
โ Most asked interview topic
โ Combines business data from multiple tables
๐ฏ Todayโs Goal
โ Understand INNER JOIN
โ Learn LEFT/RIGHT/FULL JOIN
โ Understand real-world use cases
SQL Notes: https://whatsapp.com/channel/0029VbCyzS02ZjCwoShXXc2j
๐ฌ Tap โค๏ธ for more!