SlideShare a Scribd company logo
DBMS
Joins in Relational
Algebra
Understanding Inner and Outer Joins
Natural Join
• Natural Join combines the tables based on
columns with the same name and data type.
• Automatically matches common columns
between tables.
• SQL: SELECT * FROM Employees NATURAL JOIN
Departments;
• PQL: Employees Departments
⋈
emp_id name dept_id
101 Alice 1
102 Bob 2
103 Charlie 1
104 David 3
105 Eva NULL
dept_id dept_name
1 HR
2 Engineering
3 Marketing
4 Finance
Example - Natural Join
emp_id name dept_id dept_name
101 Alice 1 HR
102 Bob 2 Engineering
103 Charlie 1 HR
104 David 3 Marketing
Employees Departments
⋈
Employees Departments
Theta Join
• Theta Join combines the tables based on a
specified condition (not necessarily equality).
• Conditional Operators incudes: >,<, <=, >= etc.
SQL –
SELECT * FROM Employees E, Departments D
WHERE E.dept_id < D.dept_id;
PQL-
Employees⋈(E.dept_id<D.dept_id) Departments
emp_id name dept_id
101 Alice 1
102 Bob 2
103 Charlie 1
105 Eva NULL
dept_id dept_name
1 HR
2 Engineering
3 Marketing
4 Finance
Example - Theta Join
Employees (E.dept_id < D.dept_id) Departments
⋈
Employees Departments
emp_id name dept_id dept_id dept_name
101 Alice 1 2 Engineering
101 Alice 1 3 Marketing
101 Alice 1 4 Finance
102 Bob 2 3 Marketing
102 Bob 2 4 Finance
103 Charlie 1 2 Engineering
103 Charlie 1 3 Marketing
103 Charlie 1 4 Finance
Equi Join
• Joins tables based on equality between
specified columns.
SQL-
SELECT * FROM Employees E, Departments D
WHERE E.dept_id =
D.dept_id;
PQL-
Employees⋈(E.dept_id=D.dept_id) Departments
dept_id dept_name
1 HR
2 Engineering
3 Marketing
4 Finance
Example - Equi Join
Employees (E.dept_id = D.dept_id) Departments
⋈
Employees Departments
emp_id name dept_id dept_id dept_name
101 Alice 1 1 HR
102 Bob 2 2 Engineering
103 Charlie 1 1 HR
104 David 3 3 Marketing
emp_id name dept_id
101 Alice 1
102 Bob 2
103 Charlie 1
104 David 3
105 Eva NULL
Outer Joins
• Outer Joins Returns matching rows plus
unmatched rows from one or both tables.
• Types:
1. Left Outer Join
2. Right Outer Join
3. Full Outer Join
Left Outer Join
• It returns all rows from the left table and
matching rows from the right table.
SQL-
SELECT * FROM Employees E LEFT OUTER JOIN
Departments D ON E.dept_id = D.dept_id;
PQL-
π*​
(Employees (E.dept_id=D.dept_id)​Departments)
⟕
dept_id dept_name
1 HR
2 Engineering
3 Marketing
4 Finance
Example – Left Outer Join
Employees (E.dept_id = D.dept_id) Departments
⟕
Employees Departments
emp_id name dept_id
101 Alice 1
102 Bob 2
103 Charlie 1
104 David 3
105 Eva NULL
emp_id name dept_id dept_id dept_name
101 Alice 1 1 HR
102 Bob 2 2 Engineering
103 Charlie 1 1 HR
104 David 3 3 Marketing
105 Eva NULL NULL NULL
Right Outer Join
• It returns all rows from the right table and
matching rows from the left table.
SQL-
SELECT * FROM Employees E RIGHT OUTER JOIN
Departments D ON E.dept_id = D.dept_id;
PQL-
π* ​
(Employees ⟖ (E.dept_id=D.dept_id) ​
Departments)
dept_id dept_name
1 HR
2 Engineering
3 Marketing
4 Finance
Example – Right Outer Join
Employees (E.dept_id = D.dept_id) Departments
⟖
Employees Departments
emp_id name dept_id
101 Alice 1
102 Bob 2
103 Charlie 1
104 David 3
105 Eva NULL
emp_id name dept_id dept_id dept_name
101 Alice 1 1 HR
103 Charlie 1 1 HR
102 Bob 2 2 Engineering
104 David 3 3 Marketing
NULL NULL NULL 4 Finance
Full Outer Join
• It returns all rows when there's a match in
either the left or right table.
SQL –
SELECT * FROM Employees E FULL OUTER JOIN
Departments D ON E.dept_id = D.dept_id;
PQL –
π*(Employees (
⟗ E.dept_id=D.dept_id) ​
Departments)
dept_id dept_name
1 HR
2 Engineering
3 Marketing
4 Finance
Example – Full Outer Join
Employees (E.dept_id = D.dept_id) Departments
⟗
Employees Departments
emp_id name dept_id
101 Alice 1
102 Bob 2
103 Charlie 1
104 David 3
105 Eva NULL
emp_id name dept_id dept_name
101 Alice 1 HR
102 Bob 2 Engineering
103 Charlie 1 HR
104 David 3 Marketing
105 Eva NULL NULL
NULL NULL 4 Finance
Join Type Definition
Includes
Matching
Rows?
Includes Non-
Matching Rows?
Natural Join
Joins based on common column(s) with the
same name and data type.
Yes No
Theta Join
Joins based on a condition other than
equality (e.g., <, >, !=).
Yes No
Equi Join
Joins based on equality between specific
columns.
Yes No
Left Outer
Join
Returns all rows from the left table, plus
matching rows from the right table. Non-
matching right table values are filled with
NULL.
Yes Left table only
Right Outer
Join
Returns all rows from the right table, plus
matching rows from the left table. Non-
matching left table values are filled with
NULL.
Yes Right table only
Full Outer
Join
Returns all rows when there is a match in
either table. Non-matching values from both
tables are filled with NULL.
Yes Both tables
Thank You

More Related Content

PDF
Relational Database and Relational Algebra
Pyingkodi Maran
 
PPTX
Querying_with_T-SQL_-_03 (1).pptx
MAHIN33
 
PPTX
Querying_with_T-SQL_-_03.pptx
MAHIN33
 
PPTX
Sql joins
Siddhesh Palkar
 
PPT
Sql Server 2000
Om Vikram Thapa
 
PPT
Displaying data from multiple tables
Syed Zaid Irshad
 
PPTX
Sql statements function join
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
Relational Database and Relational Algebra
Pyingkodi Maran
 
Querying_with_T-SQL_-_03 (1).pptx
MAHIN33
 
Querying_with_T-SQL_-_03.pptx
MAHIN33
 
Sql joins
Siddhesh Palkar
 
Sql Server 2000
Om Vikram Thapa
 
Displaying data from multiple tables
Syed Zaid Irshad
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 

Similar to Joins.pptxjjbmmmnnnnnjjjxrhjfluflurulrdudlu (20)

PPTX
SQL Server Learning Drive
TechandMate
 
PPTX
REC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptx
Uma Kakarlapudi
 
PPTX
Interacting with Oracle Database
Chhom Karath
 
PPTX
SQL.pptx
AmitDas125851
 
PPTX
SQL Join's
Muhammad Noman Fazil
 
PDF
SQL JOINS
PuNeEt KuMaR
 
PDF
sql language
moman abde
 
PPTX
Introduction to mysql part 2
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Statements,joins and operators in sql by thanveer danish melayi(1)
Muhammed Thanveer M
 
PPTX
Basic SQL Statments
Umair Shakir
 
PDF
1695304562_RELATIONAL_ALGEBRA.pdf
Kavinilaa
 
PPT
Unit2 -DBMS.ppt with type of job operation
shindhe1098cv
 
PPTX
OracleSQLraining.pptx
Rajendra Jain
 
PDF
Lesson 6 - Relational Algebra.pdf
HasankaWijesinghe1
 
PPTX
Sql 
statements , functions & joins
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
wrushabhsirsat
 
PPTX
Fundamentals of Database management system Lab Manual.pptx
Getnet Tigabie Askale -(GM)
 
PPT
Sql 2006
Cathie101
 
SQL Server Learning Drive
TechandMate
 
REC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptx
Uma Kakarlapudi
 
Interacting with Oracle Database
Chhom Karath
 
SQL.pptx
AmitDas125851
 
SQL JOINS
PuNeEt KuMaR
 
sql language
moman abde
 
Statements,joins and operators in sql by thanveer danish melayi(1)
Muhammed Thanveer M
 
Basic SQL Statments
Umair Shakir
 
1695304562_RELATIONAL_ALGEBRA.pdf
Kavinilaa
 
Unit2 -DBMS.ppt with type of job operation
shindhe1098cv
 
OracleSQLraining.pptx
Rajendra Jain
 
Lesson 6 - Relational Algebra.pdf
HasankaWijesinghe1
 
Sql 
statements , functions & joins
baabtra.com - No. 1 supplier of quality freshers
 
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
wrushabhsirsat
 
Fundamentals of Database management system Lab Manual.pptx
Getnet Tigabie Askale -(GM)
 
Sql 2006
Cathie101
 
Ad

Recently uploaded (20)

PPTX
INTERNET OF THINGS (IOT) network of interconnected devices.
rp1256748
 
PPTX
cocomo-220726173706-141e08f0.tyuiuuupptx
DharaniMani4
 
PPTX
Intro_S4HANA_Using_Global_Bike_Slides_SD_en_v4.1.pptx
trishalasharma7
 
PDF
INTEL CPU 3RD GEN.pdf variadas de computacion
juancardozzo26
 
PPTX
Boolean Algebra-Properties and Theorems.pptx
bhavanavarri5458
 
PPTX
Query and optimizing operating system.pptx
YoomifTube
 
PPTX
13. ANAESTHETICS AND ALCOHOLS.pptx fucking
sriramraja650
 
PPTX
Aryanbarot28.pptx Introduction of window os for the projects
aryanbarot004
 
PPTX
PHISHING ATTACKS. _. _.pptx[]
kumarrana7525
 
PPTX
DOC-20250728-WAprocess releases large amounts of carbon dioxide (CO₂), sulfur...
samt56673
 
PPTX
PPT on the topic of programming language
dishasindhava
 
PPT
L1-Intro.ppt nhfjkhghjjnnnmkkjhigtyhhjjj
MdKarimUllahEmon
 
PPTX
Basics of Memristors from zero to hero.pptx
onterusmail
 
PDF
Top 10 Client Success Story_ The Buy Snapchat Account Experience.pdf
Telegram Accounts
 
PPTX
Final Draft Presentation for dtaa and direct tax
rajbhanushali3981
 
PPTX
Mobile-Device-Management-MDM-Architecture.pptx
pranavnandwanshi99
 
PPTX
sample 1mathssscpreprationfor basics.PPTX
yuyutsugupta3
 
PPT
community diagnosis slides show health. ppt
michaelbrucebwana
 
PPTX
Boolean Algebra-Properties and Theorems.pptx
bhavanavarri5458
 
PPTX
Drone.pptx this is the word like a good time to come over and watch the kids
MausamJha6
 
INTERNET OF THINGS (IOT) network of interconnected devices.
rp1256748
 
cocomo-220726173706-141e08f0.tyuiuuupptx
DharaniMani4
 
Intro_S4HANA_Using_Global_Bike_Slides_SD_en_v4.1.pptx
trishalasharma7
 
INTEL CPU 3RD GEN.pdf variadas de computacion
juancardozzo26
 
Boolean Algebra-Properties and Theorems.pptx
bhavanavarri5458
 
Query and optimizing operating system.pptx
YoomifTube
 
13. ANAESTHETICS AND ALCOHOLS.pptx fucking
sriramraja650
 
Aryanbarot28.pptx Introduction of window os for the projects
aryanbarot004
 
PHISHING ATTACKS. _. _.pptx[]
kumarrana7525
 
DOC-20250728-WAprocess releases large amounts of carbon dioxide (CO₂), sulfur...
samt56673
 
PPT on the topic of programming language
dishasindhava
 
L1-Intro.ppt nhfjkhghjjnnnmkkjhigtyhhjjj
MdKarimUllahEmon
 
Basics of Memristors from zero to hero.pptx
onterusmail
 
Top 10 Client Success Story_ The Buy Snapchat Account Experience.pdf
Telegram Accounts
 
Final Draft Presentation for dtaa and direct tax
rajbhanushali3981
 
Mobile-Device-Management-MDM-Architecture.pptx
pranavnandwanshi99
 
sample 1mathssscpreprationfor basics.PPTX
yuyutsugupta3
 
community diagnosis slides show health. ppt
michaelbrucebwana
 
Boolean Algebra-Properties and Theorems.pptx
bhavanavarri5458
 
Drone.pptx this is the word like a good time to come over and watch the kids
MausamJha6
 
Ad

Joins.pptxjjbmmmnnnnnjjjxrhjfluflurulrdudlu

  • 2. Natural Join • Natural Join combines the tables based on columns with the same name and data type. • Automatically matches common columns between tables. • SQL: SELECT * FROM Employees NATURAL JOIN Departments; • PQL: Employees Departments ⋈
  • 3. emp_id name dept_id 101 Alice 1 102 Bob 2 103 Charlie 1 104 David 3 105 Eva NULL dept_id dept_name 1 HR 2 Engineering 3 Marketing 4 Finance Example - Natural Join emp_id name dept_id dept_name 101 Alice 1 HR 102 Bob 2 Engineering 103 Charlie 1 HR 104 David 3 Marketing Employees Departments ⋈ Employees Departments
  • 4. Theta Join • Theta Join combines the tables based on a specified condition (not necessarily equality). • Conditional Operators incudes: >,<, <=, >= etc. SQL – SELECT * FROM Employees E, Departments D WHERE E.dept_id < D.dept_id; PQL- Employees⋈(E.dept_id<D.dept_id) Departments
  • 5. emp_id name dept_id 101 Alice 1 102 Bob 2 103 Charlie 1 105 Eva NULL dept_id dept_name 1 HR 2 Engineering 3 Marketing 4 Finance Example - Theta Join Employees (E.dept_id < D.dept_id) Departments ⋈ Employees Departments emp_id name dept_id dept_id dept_name 101 Alice 1 2 Engineering 101 Alice 1 3 Marketing 101 Alice 1 4 Finance 102 Bob 2 3 Marketing 102 Bob 2 4 Finance 103 Charlie 1 2 Engineering 103 Charlie 1 3 Marketing 103 Charlie 1 4 Finance
  • 6. Equi Join • Joins tables based on equality between specified columns. SQL- SELECT * FROM Employees E, Departments D WHERE E.dept_id = D.dept_id; PQL- Employees⋈(E.dept_id=D.dept_id) Departments
  • 7. dept_id dept_name 1 HR 2 Engineering 3 Marketing 4 Finance Example - Equi Join Employees (E.dept_id = D.dept_id) Departments ⋈ Employees Departments emp_id name dept_id dept_id dept_name 101 Alice 1 1 HR 102 Bob 2 2 Engineering 103 Charlie 1 1 HR 104 David 3 3 Marketing emp_id name dept_id 101 Alice 1 102 Bob 2 103 Charlie 1 104 David 3 105 Eva NULL
  • 8. Outer Joins • Outer Joins Returns matching rows plus unmatched rows from one or both tables. • Types: 1. Left Outer Join 2. Right Outer Join 3. Full Outer Join
  • 9. Left Outer Join • It returns all rows from the left table and matching rows from the right table. SQL- SELECT * FROM Employees E LEFT OUTER JOIN Departments D ON E.dept_id = D.dept_id; PQL- π*​ (Employees (E.dept_id=D.dept_id)​Departments) ⟕
  • 10. dept_id dept_name 1 HR 2 Engineering 3 Marketing 4 Finance Example – Left Outer Join Employees (E.dept_id = D.dept_id) Departments ⟕ Employees Departments emp_id name dept_id 101 Alice 1 102 Bob 2 103 Charlie 1 104 David 3 105 Eva NULL emp_id name dept_id dept_id dept_name 101 Alice 1 1 HR 102 Bob 2 2 Engineering 103 Charlie 1 1 HR 104 David 3 3 Marketing 105 Eva NULL NULL NULL
  • 11. Right Outer Join • It returns all rows from the right table and matching rows from the left table. SQL- SELECT * FROM Employees E RIGHT OUTER JOIN Departments D ON E.dept_id = D.dept_id; PQL- π* ​ (Employees ⟖ (E.dept_id=D.dept_id) ​ Departments)
  • 12. dept_id dept_name 1 HR 2 Engineering 3 Marketing 4 Finance Example – Right Outer Join Employees (E.dept_id = D.dept_id) Departments ⟖ Employees Departments emp_id name dept_id 101 Alice 1 102 Bob 2 103 Charlie 1 104 David 3 105 Eva NULL emp_id name dept_id dept_id dept_name 101 Alice 1 1 HR 103 Charlie 1 1 HR 102 Bob 2 2 Engineering 104 David 3 3 Marketing NULL NULL NULL 4 Finance
  • 13. Full Outer Join • It returns all rows when there's a match in either the left or right table. SQL – SELECT * FROM Employees E FULL OUTER JOIN Departments D ON E.dept_id = D.dept_id; PQL – π*(Employees ( ⟗ E.dept_id=D.dept_id) ​ Departments)
  • 14. dept_id dept_name 1 HR 2 Engineering 3 Marketing 4 Finance Example – Full Outer Join Employees (E.dept_id = D.dept_id) Departments ⟗ Employees Departments emp_id name dept_id 101 Alice 1 102 Bob 2 103 Charlie 1 104 David 3 105 Eva NULL emp_id name dept_id dept_name 101 Alice 1 HR 102 Bob 2 Engineering 103 Charlie 1 HR 104 David 3 Marketing 105 Eva NULL NULL NULL NULL 4 Finance
  • 15. Join Type Definition Includes Matching Rows? Includes Non- Matching Rows? Natural Join Joins based on common column(s) with the same name and data type. Yes No Theta Join Joins based on a condition other than equality (e.g., <, >, !=). Yes No Equi Join Joins based on equality between specific columns. Yes No Left Outer Join Returns all rows from the left table, plus matching rows from the right table. Non- matching right table values are filled with NULL. Yes Left table only Right Outer Join Returns all rows from the right table, plus matching rows from the left table. Non- matching left table values are filled with NULL. Yes Right table only Full Outer Join Returns all rows when there is a match in either table. Non-matching values from both tables are filled with NULL. Yes Both tables