SlideShare a Scribd company logo
Advance Database Systems
Joining Concepts in Advanced SQL
Contents
• Join
• Cross Join
• Inner Join
• Outer Join
Join
• An SQL join clause combines records from two or more than two
tables in a relational database system.
• A JOIN is a means for combining fields from two tables(or more) by
using values.
• SQL specifies five types of JOIN:
• INNER, LEFT OUTER, RIGHT OUTER, FULL OUTER and CROSS.
• As a special case, a table(base table, view, or joined table) can JOIN to
itself in a self-join.
Advance database system(part 8)
• Joining separate tables for DEPARTMENT and EMPLOYEE effectively
creates another table which combines the information from both
tables.
• In the following tables on next slide, the DepartmentID column of the
Department table which may be designated as Department.
DepartmentID is the primary key, while Employee. DepartmentID is
the foreign key.
• Sample Tables:
Cross Join
• Cross Join returns the Cartesian product of rows from tables in the join.
• In other words, it will produce rows which combine each row from the first
table with each row from the second table.
• Example of an Explicit cross join:
• --MySQL Query
• SELECT * from JOINING.EMPLOYEE
• CROS JOIN
• JOINING. Department ORDER BY `CROS`.`DepartmentID` ASC
• Example of an Implicit cross join:
• --MySQL Query
• SELECT * from `JOINING`.`EMPLOYEE` , `JOINING`.`Department`
Advance database system(part 8)
Inner Join
• An inner join requires each record in the two joined tables to have
matching records.
• Inner join creates a new result table by combining column values of two
tables(A and B) based upon the join-condition.
• The query compares each row of A with each row of B to find all pairs of
rows which satisfy the join-condition.
• When the join-condition is satisfied by matching non-NULL values, column
values for each matched pair of rows of A and B are combined in to a result
row.
• The result of the join can be defined as the outcome of first taking the
Cartesian product(or Cross join) of all records in the tables(combining every
record in table A with every record in table B) and then returning all
records which satisfy the join condition.
• The “Explicit join notation“ uses the JOIN key word, optionally
preceded by the INNER key word, to specify the table to join, and the
ON key word to specify the condition for the join, as in the following
example:
--MySQL query
SELECT * from `JOINING`.`EMPLOYEE`
Inner JOIN `JOINING`.`Department`
ON Employee. DepartmentID= department. DepartmentID
ORDER BY `EMPLOYEE`.`DepartmentID` ASC;
• using Implicit join notation:
• --MySQL Query
• SELECT * from `JOINING`.`EMPLOYEE` , `JOINING`.`Department`
• WHERE
• `EMPLOYEE`.`DEPARTMENTID` = `DEPARTMENT`.`DEPARTMENTID`;
• The queries given in the examples above will join the Employee and
Department tables using the DepartmentID column of both tables.
Where the DepartmentID of these tables match.
• (i. e. the join- condition is satisfied), the query will combine the Last
Name, DepartmentID and DepartmentName columns from the two
tables in to a result row. Where the DepartmentID does not match,
no result row is generated.
Thus, the result of the execution of either of the
two queries will be:
Notice that the employee "Williams“ and the department
“Marketing“ did not appear in the query execution results and no
employee has the departmentID 35 ("Marketing").
Outer Join
• An outer join does not require each record in the two joined tables to
have a matching record.
• The joined table retains each record; even if no other matching record
exists.
• Outer joins subdivide further into left outer joins, right outer joins,
and full outer joins, depending on which table's rows are retained
(left, right, or both)
• (In this case left and right refer to the two sides of the JOIN key word.)
• No implicit join-notation for outer joins exists in standard SQL.
Left Outer Join
• The result of a left outer join(or simply left join) for tables A and B
always contains all records of the "left“ table(A), even if the join
condition does not find any matching record in the "right“ table(B).
• This means that if the ON clause matches 0(zero) records in B(for a
given record in A), the join will still return a row in the result(for that
record) but with NULL in each column from B.
• A left outer join returns all the values from an inner join plus all
values in the left table that do not match to the right table, including
rows with NULL(empty) values in the link field.
• Example of a left outer join (the OUTER keyword is optional), with the
additional result row (compared with the inner join):
--MySQL Query
SELECT * from `JOINING`.`EMPLOYEE`
LEFT OUTER JOIN `DEPARTMENT`
ON `EMPLOYEE`.`DEPARTMENTID` = `DEPARTMENT`.`DEPARTMENTID`;
Right Outer Join
• A right outer join(or right join) closely resembles a left outer join,
except with the treatment of the tables.
• Every row from the "right“ table(B) will appear in the joined table at
least once. If no matching row from the "left“ table(A) exists, NULL
will appear in columns from A for those records that have no match in
B.
• A right outer join returns all the values from the right table and
matched values from the left table(NULL in the case of no matching in
predicate).
• For example, this allows us to find each employee and his or her
department, but still show departments that have no employees.
Below is an example of a right outer join (the
OUTER keyword is optional):
--MySQL Query
SELECT * from `JOINING`.`EMPLOYEE`
RIGHT OUTER JOIN `DEPARTMENT`
ON `EMPLOYEE`.`DEPARTMENTID` = `DEPARTMENT`.`DEPARTMENTID`;
Full Outer Join
• Conceptually, a full outer join combines the effect of applying both
left and right outer joins.
• Also, records in the FULL OUTER JOIN tables do not match; the result
set will have NULL values for every column of the table that lacks a
matching row. For those records that do match, a single row will be
produced in the result set(containing fields populated from both
tables).
• For example, this allows us to see each employee who is in a
department and each department that has an employee, but also see
each employee who is not part of a department and each department
which doesn‘t have an employee.
Below is an example of a full Outer Join:
--MySQL Query (In MySQL; UNION operator is used to achieve Full
Outer Join)
SELECT * from `JOINING`.`EMPLOYEE`
LEFT JOIN `JOINING`.`DEPARTMENT`
ON `EMPLOYEE`.`DEPARTMENTID` = `DEPARTMENT`.`DEPARTMENTID`
UNION
SELECT * FROM `JOINING`.`EMPLOYEE`
RIGHT JOIN`JOINING`.`DEPARTMENT`
ON `EMPLOYEE`.`DEPARTMENTID` = `DEPARTMENT`.`DEPARTMENTID`;
Advance database system(part 8)
Ad

More Related Content

What's hot (20)

Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
programmings guru
 
Mysql joins
Mysql joinsMysql joins
Mysql joins
baabtra.com - No. 1 supplier of quality freshers
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
Vigneshwaran Sankaran
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
oracle content
 
Sql joins
Sql joinsSql joins
Sql joins
Gaurav Dhanwant
 
Inner join and outer join
Inner join and outer joinInner join and outer join
Inner join and outer join
Nargis Ehsan
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
BG Java EE Course
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
Raveena Thakur
 
Join sql
Join sqlJoin sql
Join sql
Vikas Gupta
 
joins and subqueries in big data analysis
joins and subqueries in big data analysisjoins and subqueries in big data analysis
joins and subqueries in big data analysis
SanSan149
 
SQL select clause
SQL select clauseSQL select clause
SQL select clause
arpit bhadoriya
 
Sql commands
Sql commandsSql commands
Sql commands
Pooja Dixit
 
Using SQL Queries to Insert, Update, Delete, and View Data.ppt
Using SQL Queries to Insert, Update, Delete, and View Data.pptUsing SQL Queries to Insert, Update, Delete, and View Data.ppt
Using SQL Queries to Insert, Update, Delete, and View Data.ppt
MohammedJifar1
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
Swapnali Pawar
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
Stewart Rogers
 
SQL Joins With Examples | Edureka
SQL Joins With Examples | EdurekaSQL Joins With Examples | Edureka
SQL Joins With Examples | Edureka
Edureka!
 
Group By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQLGroup By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQL
MSB Academy
 
Conditional formatting in excel v2
Conditional formatting in excel v2Conditional formatting in excel v2
Conditional formatting in excel v2
m182348
 
Database Triggers
Database TriggersDatabase Triggers
Database Triggers
Aliya Saldanha
 
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joins
Deepthi Rachumallu
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
programmings guru
 
Inner join and outer join
Inner join and outer joinInner join and outer join
Inner join and outer join
Nargis Ehsan
 
joins and subqueries in big data analysis
joins and subqueries in big data analysisjoins and subqueries in big data analysis
joins and subqueries in big data analysis
SanSan149
 
Using SQL Queries to Insert, Update, Delete, and View Data.ppt
Using SQL Queries to Insert, Update, Delete, and View Data.pptUsing SQL Queries to Insert, Update, Delete, and View Data.ppt
Using SQL Queries to Insert, Update, Delete, and View Data.ppt
MohammedJifar1
 
SQL Joins With Examples | Edureka
SQL Joins With Examples | EdurekaSQL Joins With Examples | Edureka
SQL Joins With Examples | Edureka
Edureka!
 
Group By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQLGroup By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQL
MSB Academy
 
Conditional formatting in excel v2
Conditional formatting in excel v2Conditional formatting in excel v2
Conditional formatting in excel v2
m182348
 
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joins
Deepthi Rachumallu
 

Similar to Advance database system(part 8) (20)

Join
JoinJoin
Join
Kanchana Rani G
 
The Relational Database Model 2 univprsty
The Relational Database Model 2 univprstyThe Relational Database Model 2 univprsty
The Relational Database Model 2 univprsty
ErickWasonga2
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
Ahmed Farag
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai1
 
SQL Join's
SQL Join'sSQL Join's
SQL Join's
Muhammad Noman Fazil
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
PuNeEt KuMaR
 
Join query
Join queryJoin query
Join query
Waqar Ali
 
Join in SQL - Inner, Self, Outer Join
Join in SQL - Inner, Self, Outer JoinJoin in SQL - Inner, Self, Outer Join
Join in SQL - Inner, Self, Outer Join
Souma Maiti
 
Sql
SqlSql
Sql
RittikaBaksi
 
database .pptx
database .pptxdatabase .pptx
database .pptx
Mohammad Adnan
 
Assignment 4
Assignment 4Assignment 4
Assignment 4
SneaK3
 
sqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwf
sqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwfsqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwf
sqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwf
kailasmanoj
 
sql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrk
sql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrksql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrk
sql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrk
kailasmanoj
 
REC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptx
REC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptxREC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptx
REC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptx
Uma Kakarlapudi
 
Joins SQL Server
Joins SQL ServerJoins SQL Server
Joins SQL Server
baabtra.com - No. 1 supplier of quality freshers
 
Lesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdfLesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdf
HasankaWijesinghe1
 
Sql joins
Sql joinsSql joins
Sql joins
LokeshGogia2
 
SQL JOIN.pptx
SQL JOIN.pptxSQL JOIN.pptx
SQL JOIN.pptx
johnwick814916
 
joins in dbms its describes about how joins are important and necessity in d...
joins in dbms  its describes about how joins are important and necessity in d...joins in dbms  its describes about how joins are important and necessity in d...
joins in dbms its describes about how joins are important and necessity in d...
AshokRachapalli1
 
The Relational Database Model 2 univprsty
The Relational Database Model 2 univprstyThe Relational Database Model 2 univprsty
The Relational Database Model 2 univprsty
ErickWasonga2
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai1
 
Join in SQL - Inner, Self, Outer Join
Join in SQL - Inner, Self, Outer JoinJoin in SQL - Inner, Self, Outer Join
Join in SQL - Inner, Self, Outer Join
Souma Maiti
 
Assignment 4
Assignment 4Assignment 4
Assignment 4
SneaK3
 
sqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwf
sqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwfsqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwf
sqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwf
kailasmanoj
 
sql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrk
sql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrksql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrk
sql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrk
kailasmanoj
 
REC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptx
REC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptxREC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptx
REC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptx
Uma Kakarlapudi
 
Lesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdfLesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdf
HasankaWijesinghe1
 
joins in dbms its describes about how joins are important and necessity in d...
joins in dbms  its describes about how joins are important and necessity in d...joins in dbms  its describes about how joins are important and necessity in d...
joins in dbms its describes about how joins are important and necessity in d...
AshokRachapalli1
 
Ad

More from Abdullah Khosa (20)

Chanel and H&M Brand Comparison.pdf
Chanel and H&M Brand Comparison.pdfChanel and H&M Brand Comparison.pdf
Chanel and H&M Brand Comparison.pdf
Abdullah Khosa
 
Mycin presentation
Mycin presentationMycin presentation
Mycin presentation
Abdullah Khosa
 
Policy directives of federal government of pakistan for Enterprise Architecture
Policy directives of federal government of pakistan for Enterprise ArchitecturePolicy directives of federal government of pakistan for Enterprise Architecture
Policy directives of federal government of pakistan for Enterprise Architecture
Abdullah Khosa
 
Face to Face Communication and Text Based Communication in HCI
Face to Face Communication and Text Based Communication in HCIFace to Face Communication and Text Based Communication in HCI
Face to Face Communication and Text Based Communication in HCI
Abdullah Khosa
 
STRATEGIC PAY PLANS
STRATEGIC PAY PLANSSTRATEGIC PAY PLANS
STRATEGIC PAY PLANS
Abdullah Khosa
 
AI services in google
AI services in googleAI services in google
AI services in google
Abdullah Khosa
 
Cloud Artificial Intelligence services
Cloud Artificial Intelligence servicesCloud Artificial Intelligence services
Cloud Artificial Intelligence services
Abdullah Khosa
 
Digital centralization
Digital centralizationDigital centralization
Digital centralization
Abdullah Khosa
 
Diamond water-paradox (A Theory)
Diamond water-paradox (A Theory)Diamond water-paradox (A Theory)
Diamond water-paradox (A Theory)
Abdullah Khosa
 
The 5th generation (5G)
The 5th generation (5G)The 5th generation (5G)
The 5th generation (5G)
Abdullah Khosa
 
Report of database of list of Pakistan international cricket stadiums
Report of database of list of Pakistan international cricket stadiumsReport of database of list of Pakistan international cricket stadiums
Report of database of list of Pakistan international cricket stadiums
Abdullah Khosa
 
Database of list of Pakistan international cricket stadiums
Database of list of Pakistan international cricket stadiumsDatabase of list of Pakistan international cricket stadiums
Database of list of Pakistan international cricket stadiums
Abdullah Khosa
 
Attitude and behavior
Attitude and behaviorAttitude and behavior
Attitude and behavior
Abdullah Khosa
 
Digital signature
Digital signatureDigital signature
Digital signature
Abdullah Khosa
 
Benefits of Search engine optimization
Benefits of Search engine optimizationBenefits of Search engine optimization
Benefits of Search engine optimization
Abdullah Khosa
 
Physical Database Design & Performance
Physical Database Design & PerformancePhysical Database Design & Performance
Physical Database Design & Performance
Abdullah Khosa
 
Advanced Normalization
Advanced NormalizationAdvanced Normalization
Advanced Normalization
Abdullah Khosa
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
Abdullah Khosa
 
Advance database system(part 7)
Advance database system(part 7)Advance database system(part 7)
Advance database system(part 7)
Abdullah Khosa
 
Advance database system(part 6)
Advance database system(part 6)Advance database system(part 6)
Advance database system(part 6)
Abdullah Khosa
 
Chanel and H&M Brand Comparison.pdf
Chanel and H&M Brand Comparison.pdfChanel and H&M Brand Comparison.pdf
Chanel and H&M Brand Comparison.pdf
Abdullah Khosa
 
Policy directives of federal government of pakistan for Enterprise Architecture
Policy directives of federal government of pakistan for Enterprise ArchitecturePolicy directives of federal government of pakistan for Enterprise Architecture
Policy directives of federal government of pakistan for Enterprise Architecture
Abdullah Khosa
 
Face to Face Communication and Text Based Communication in HCI
Face to Face Communication and Text Based Communication in HCIFace to Face Communication and Text Based Communication in HCI
Face to Face Communication and Text Based Communication in HCI
Abdullah Khosa
 
Cloud Artificial Intelligence services
Cloud Artificial Intelligence servicesCloud Artificial Intelligence services
Cloud Artificial Intelligence services
Abdullah Khosa
 
Digital centralization
Digital centralizationDigital centralization
Digital centralization
Abdullah Khosa
 
Diamond water-paradox (A Theory)
Diamond water-paradox (A Theory)Diamond water-paradox (A Theory)
Diamond water-paradox (A Theory)
Abdullah Khosa
 
The 5th generation (5G)
The 5th generation (5G)The 5th generation (5G)
The 5th generation (5G)
Abdullah Khosa
 
Report of database of list of Pakistan international cricket stadiums
Report of database of list of Pakistan international cricket stadiumsReport of database of list of Pakistan international cricket stadiums
Report of database of list of Pakistan international cricket stadiums
Abdullah Khosa
 
Database of list of Pakistan international cricket stadiums
Database of list of Pakistan international cricket stadiumsDatabase of list of Pakistan international cricket stadiums
Database of list of Pakistan international cricket stadiums
Abdullah Khosa
 
Benefits of Search engine optimization
Benefits of Search engine optimizationBenefits of Search engine optimization
Benefits of Search engine optimization
Abdullah Khosa
 
Physical Database Design & Performance
Physical Database Design & PerformancePhysical Database Design & Performance
Physical Database Design & Performance
Abdullah Khosa
 
Advanced Normalization
Advanced NormalizationAdvanced Normalization
Advanced Normalization
Abdullah Khosa
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
Abdullah Khosa
 
Advance database system(part 7)
Advance database system(part 7)Advance database system(part 7)
Advance database system(part 7)
Abdullah Khosa
 
Advance database system(part 6)
Advance database system(part 6)Advance database system(part 6)
Advance database system(part 6)
Abdullah Khosa
 
Ad

Recently uploaded (20)

Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Sugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptxSugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptx
Dr. Renu Jangid
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Sugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptxSugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptx
Dr. Renu Jangid
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 

Advance database system(part 8)

  • 1. Advance Database Systems Joining Concepts in Advanced SQL
  • 2. Contents • Join • Cross Join • Inner Join • Outer Join
  • 3. Join • An SQL join clause combines records from two or more than two tables in a relational database system. • A JOIN is a means for combining fields from two tables(or more) by using values. • SQL specifies five types of JOIN: • INNER, LEFT OUTER, RIGHT OUTER, FULL OUTER and CROSS. • As a special case, a table(base table, view, or joined table) can JOIN to itself in a self-join.
  • 5. • Joining separate tables for DEPARTMENT and EMPLOYEE effectively creates another table which combines the information from both tables. • In the following tables on next slide, the DepartmentID column of the Department table which may be designated as Department. DepartmentID is the primary key, while Employee. DepartmentID is the foreign key. • Sample Tables:
  • 6. Cross Join • Cross Join returns the Cartesian product of rows from tables in the join. • In other words, it will produce rows which combine each row from the first table with each row from the second table. • Example of an Explicit cross join: • --MySQL Query • SELECT * from JOINING.EMPLOYEE • CROS JOIN • JOINING. Department ORDER BY `CROS`.`DepartmentID` ASC • Example of an Implicit cross join: • --MySQL Query • SELECT * from `JOINING`.`EMPLOYEE` , `JOINING`.`Department`
  • 8. Inner Join • An inner join requires each record in the two joined tables to have matching records. • Inner join creates a new result table by combining column values of two tables(A and B) based upon the join-condition. • The query compares each row of A with each row of B to find all pairs of rows which satisfy the join-condition. • When the join-condition is satisfied by matching non-NULL values, column values for each matched pair of rows of A and B are combined in to a result row. • The result of the join can be defined as the outcome of first taking the Cartesian product(or Cross join) of all records in the tables(combining every record in table A with every record in table B) and then returning all records which satisfy the join condition.
  • 9. • The “Explicit join notation“ uses the JOIN key word, optionally preceded by the INNER key word, to specify the table to join, and the ON key word to specify the condition for the join, as in the following example: --MySQL query SELECT * from `JOINING`.`EMPLOYEE` Inner JOIN `JOINING`.`Department` ON Employee. DepartmentID= department. DepartmentID ORDER BY `EMPLOYEE`.`DepartmentID` ASC; • using Implicit join notation: • --MySQL Query • SELECT * from `JOINING`.`EMPLOYEE` , `JOINING`.`Department` • WHERE • `EMPLOYEE`.`DEPARTMENTID` = `DEPARTMENT`.`DEPARTMENTID`;
  • 10. • The queries given in the examples above will join the Employee and Department tables using the DepartmentID column of both tables. Where the DepartmentID of these tables match. • (i. e. the join- condition is satisfied), the query will combine the Last Name, DepartmentID and DepartmentName columns from the two tables in to a result row. Where the DepartmentID does not match, no result row is generated.
  • 11. Thus, the result of the execution of either of the two queries will be: Notice that the employee "Williams“ and the department “Marketing“ did not appear in the query execution results and no employee has the departmentID 35 ("Marketing").
  • 12. Outer Join • An outer join does not require each record in the two joined tables to have a matching record. • The joined table retains each record; even if no other matching record exists. • Outer joins subdivide further into left outer joins, right outer joins, and full outer joins, depending on which table's rows are retained (left, right, or both) • (In this case left and right refer to the two sides of the JOIN key word.) • No implicit join-notation for outer joins exists in standard SQL.
  • 13. Left Outer Join • The result of a left outer join(or simply left join) for tables A and B always contains all records of the "left“ table(A), even if the join condition does not find any matching record in the "right“ table(B). • This means that if the ON clause matches 0(zero) records in B(for a given record in A), the join will still return a row in the result(for that record) but with NULL in each column from B. • A left outer join returns all the values from an inner join plus all values in the left table that do not match to the right table, including rows with NULL(empty) values in the link field. • Example of a left outer join (the OUTER keyword is optional), with the additional result row (compared with the inner join):
  • 14. --MySQL Query SELECT * from `JOINING`.`EMPLOYEE` LEFT OUTER JOIN `DEPARTMENT` ON `EMPLOYEE`.`DEPARTMENTID` = `DEPARTMENT`.`DEPARTMENTID`;
  • 15. Right Outer Join • A right outer join(or right join) closely resembles a left outer join, except with the treatment of the tables. • Every row from the "right“ table(B) will appear in the joined table at least once. If no matching row from the "left“ table(A) exists, NULL will appear in columns from A for those records that have no match in B. • A right outer join returns all the values from the right table and matched values from the left table(NULL in the case of no matching in predicate). • For example, this allows us to find each employee and his or her department, but still show departments that have no employees.
  • 16. Below is an example of a right outer join (the OUTER keyword is optional): --MySQL Query SELECT * from `JOINING`.`EMPLOYEE` RIGHT OUTER JOIN `DEPARTMENT` ON `EMPLOYEE`.`DEPARTMENTID` = `DEPARTMENT`.`DEPARTMENTID`;
  • 17. Full Outer Join • Conceptually, a full outer join combines the effect of applying both left and right outer joins. • Also, records in the FULL OUTER JOIN tables do not match; the result set will have NULL values for every column of the table that lacks a matching row. For those records that do match, a single row will be produced in the result set(containing fields populated from both tables). • For example, this allows us to see each employee who is in a department and each department that has an employee, but also see each employee who is not part of a department and each department which doesn‘t have an employee.
  • 18. Below is an example of a full Outer Join: --MySQL Query (In MySQL; UNION operator is used to achieve Full Outer Join) SELECT * from `JOINING`.`EMPLOYEE` LEFT JOIN `JOINING`.`DEPARTMENT` ON `EMPLOYEE`.`DEPARTMENTID` = `DEPARTMENT`.`DEPARTMENTID` UNION SELECT * FROM `JOINING`.`EMPLOYEE` RIGHT JOIN`JOINING`.`DEPARTMENT` ON `EMPLOYEE`.`DEPARTMENTID` = `DEPARTMENT`.`DEPARTMENTID`;