đ Lab 2.3: SQL JOINS — INNER, LEFT, RIGHT, FULL OUTER
This lab introduces SQL JOINs using real-world Bangladeshi data. JOINs allow you to combine data from two or more tables based on a related column — typically a foreign key. Let's practice with Employees and Departments tables.
đ Employees Table
emp_id | emp_name | dept_id |
---|---|---|
1 | Rakib Hossain | 10 |
2 | Sharmin Akter | 20 |
3 | Imran Kabir | NULL |
4 | Naeem Islam | 30 |
đ Departments Table
dept_id | dept_name |
---|---|
10 | IT |
20 | HR |
40 | Marketing |
đ§Ē 1. INNER JOIN
SELECT e.emp_name, d.dept_name
FROM employees e
INNER JOIN departments d
ON e.dept_id = d.dept_id;
Returns only employees who belong to a department (matched rows in both tables).
đ§Ē 2. LEFT JOIN
SELECT e.emp_name, d.dept_name
FROM employees e
LEFT JOIN departments d
ON e.dept_id = d.dept_id;
Returns all employees — even if they don’t belong to any department (e.g., Imran).
đ§Ē 3. RIGHT JOIN
SELECT e.emp_name, d.dept_name
FROM employees e
RIGHT JOIN departments d
ON e.dept_id = d.dept_id;
Returns all departments — even if no employee belongs to them (e.g., Marketing).
đ§Ē 4. FULL OUTER JOIN
SELECT e.emp_name, d.dept_name
FROM employees e
FULL OUTER JOIN departments d
ON e.dept_id = d.dept_id;
Returns all records from both tables. If there’s no match, it fills with NULL.
✅ Use JOINs when your data is spread across multiple tables and you want a combined result based on a relationship.
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ