Database System Lab-9
Database System Lab-9
Database System
JOINS
Joins are fundamental operations in relational databases used to combine rows from two or more tables
based on a related column between them.
Types of Joins
Inner Join
Left Join (or Left Outer Join)
Right Join (or Right Outer Join)
Full Join (or Full Outer Join)
Inner Join
Inner Join returns rows when there is a match in both tables being joined.
The resulting table contains only those rows where the join condition is satisfied.
SELECT columns
FROM table1
INNER JOIN table2
ON table1.column = table2.column;
Example of Inner Join
Employee Table
EmpID Name DeptID
1 Alice 101
2 Bob 102
3 Charlie 101
Department Table
DeptID DeptName
101 IT
102 HR
103 Finance
SELECT Employees.Name, Departments.DeptName
FROM Employees
INNER JOIN Departments ON Employees.DeptID = Departments.DeptID;
Name DeptName
Alice IT
Bob HR
Charlie IT
Left Join
Left Join returns all rows from the left table and the matched rows from the right table.
If no match is found, NULL values are returned for the columns of the right table.
SELECT columns
FROM table1
LEFT JOIN table2
ON table1.column = table2.column;
Example of Left Join
Name DeptName
Alice IT
Bob HR
Charlie IT
NULL Finance
Task
Write a SQL query to retrieve the names of employees along with their department names using Inner Join.
Write a SQL query to retrieve the names of employees along with their department names using Left Join.