SQL Joins Assignment
Instructions:
Use the given Employees and Departments tables to write SQL queries for the following
tasks.
Employees Table
EmployeeID Name DepartmentID Salary
1 Alice 101 60000
2 Bob 102 55000
3 Charlie 103 70000
4 David 101 65000
5 Emma NULL 50000
Departments Table
DepartmentID DepartmentName
101 HR
102 IT
103 Finance
104 Marketing
Questions:
1. INNER JOIN
Write an SQL query to retrieve employee names and their department names. Include
only employees who are assigned to a department.
2. LEFT JOIN
Write an SQL query to return all employees along with their department names.
Include employees even if they do not belong to a department.
3. RIGHT JOIN
Write an SQL query to return all departments and their employees, including
departments that do not have employees.
4. FULL JOIN
Write an SQL query to return all employees and departments, even if there is no
match between them.
5. SELF JOIN
Assume the Employees table contains a ManagerID column that references
EmployeeID. Write an SQL query to list employees along with their managers' names.
6. CARTESIAN JOIN
Write an SQL query that returns all possible employee and department combinations,
even if they are not related.
7. UNION
Write an SQL query to return a list of all employees and departments from both
Employees and Departments tables (without duplicates).
8. INTERSECTION (Common Employees in Multiple Queries)
Write an SQL query to return employees who appear in both:
A list of employees earning more than 55000
A list of employees working in IT or Finance departments