đ Combine Employee and Department Data Using SQL JOIN
To show complete information about employees and their departments, we can combine data from two tables using SQL JOIN. We'll demonstrate this using a Bangladeshi employee dataset.
đ Employees Table
emp_id | emp_name | dept_id |
---|---|---|
1 | Rakib Hossain | 10 |
2 | Sharmin Akter | 20 |
3 | Imran Kabir | NULL |
đ Departments Table
dept_id | dept_name |
---|---|
10 | IT |
20 | HR |
30 | Marketing |
đ§Ē INNER JOIN: Match Only Existing Departments
SELECT e.emp_name, d.dept_name
FROM employees e
INNER JOIN departments d
ON e.dept_id = d.dept_id;
This query returns only employees who have a valid department assigned.
đ§ž Result:
- Rakib Hossain — IT
- Sharmin Akter — HR
đ§Ē LEFT JOIN: Show All Employees, Even Without Department
SELECT e.emp_name, d.dept_name
FROM employees e
LEFT JOIN departments d
ON e.dept_id = d.dept_id;
Returns all employees. If a department is missing (NULL), it still shows the employee with blank dept_name.
đ§ž Result:
- Rakib Hossain — IT
- Sharmin Akter — HR
- Imran Kabir — (no department)
đ Summary
- INNER JOIN – Combines data only where matching dept_id exists in both tables
- LEFT JOIN – Shows all employees, including those without a department
✅ Use JOINs to bring together data from multiple tables and create meaningful reports or dashboards.
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ