0% found this document useful (0 votes)
20 views9 pages

Database System Lab-9

The document discusses different types of joins in SQL including inner joins, left joins, right joins and full joins. It provides examples of inner joins and left joins on employee and department tables to retrieve employee names and department names.

Uploaded by

Hafiz Mian 10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views9 pages

Database System Lab-9

The document discusses different types of joins in SQL including inner joins, left joins, right joins and full joins. It provides examples of inner joins and left joins on employee and department tables to retrieve employee names and department names.

Uploaded by

Hafiz Mian 10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Joins in SQL

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

SELECT Employees.Name, Departments.DeptName


FROM Employees
LEFT JOIN Departments
ON Employees.DeptID = Departments.DeptID;

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.

You might also like