SlideShare a Scribd company logo
Database Systems
Types of Joins
Syed Sarmad AliDatabase Management Systems
1
Lecture 12
Today’s agenda(Joins in database)
Natural Join
Inner Join
Equi Join
Theta Join
Semi Join
Anti Join
Cross Join
Outer Join
 Left Outer Join
 Right Outer Join
 Full Outer Join
Self Join
Database Management Systems
2
Join
 Join is a special form of cross product of two tables.
 In Cartesian product we join a tuple of one table with the tuples
of the second table. But in join there is a special requirement of
relationship between tuples.
 For example if there is a relation STUDENT and a relation BOOK
then it may be required to know that how many books have
been issued to any particular student. Now in this case the
primary key of STUDENT that is stId is a foreign key in BOOK table
through which the join can be made.
 joins in database
Natural Join
 Natural join ( ) is a binary operator that is written as (R S)
where R and S are relations.
 In particular, natural join allows the combination of relations that
are associated by a foreign key.
Natural Join (Example)
Semi Join ( ) and ( )
 The left semijoin is joining similar to the natural join and written as R S
where R and S are relation.
 The result of this semijoin is only the set of all tuples in R for which there is a
tuple in S that is equal on their common attribute names.
 For an example consider the tables Employee and Dept and their semi join:
Semi Join (Example)
SELECT * FROM departments
WHERE EXISTS
(SELECT * FROM employees WHERE departments.department_id =
employees.department_id AND employees.salary > 2500)
ORDER BY department_name;
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) one retains the rows from (left, right, or both).
Left Outer Join
 The result of a left outer join (or simply left join) for table 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, the join will still
return a row in the result—but with NULL in each column from B.
 This means that a left outer join returns all the values from the left table, plus
matched values from the right table (or NULL in case of no matching join
predicate).
 If the right table returns one row and the left table returns more than one
matching row for it, the values in the right table will be repeated for each
distinct row on the left table.
Employee
Dept
Employee =X Dept
Left Outer Join (Example)
Right Outer Join
 A right outer join (or right join) closely resembles a left outer join, except
with the treatment of the tables reversed. 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 case of no
matching join predicate).
Employee
Dept
Employee X= Dept
Right Outer Join (Example)
Full Outer Join
 Conceptually, a full outer join combines the effect of applying both left
and right outer joins. Where records in the FULL OUTER JOINed 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).
Employee
Dept
Employee =X= Dept
Full Outer Join (Example)
Cartesian Product
 In mathematics, it is a set of all pairs of elements (x, y) that can be
constructed from given sets, X and Y, such that x belongs to X and y to Y.
 It defines a relation that is the concatenation of every tuple of relation R
with every tuple of relation S.
Person City
Person X City
Inner join
 An inner join is the most common join operation used in
applications and can be regarded as the default join-type.
 Inner join creates a new result table by combining column values of
two tables (A and B) based upon the join-predicate.
 The query compares each row of A with each row of B to find all
pairs of rows which satisfy the join-predicate. When the join-
predicate is satisfied, column values for each matched pair of rows
of A and B are combined into a result row.
Equijoin
 An equi-join, also known as an equijoin, is a specific type of
comparator-based join, or theta join, that uses
only equality comparisons in the join-predicate. Using other
comparison operators (such as <) disqualifies a join as an equi-join.
 joins in database
Equijoin (Example)
θ-join
 Consider tables Car and Boat which list models of cars and boats and their
respective prices.
 Suppose a customer wants to buy a car and a boat, but she does not
want to spend more money for the boat than for the car.
 The θ-join on the relation CarPrice ≥ BoatPrice produces a table with all
the possible options. If you are using a condition where the attributes are
equal the like Price the condition may be specified as Price=Price or
alternatively (Price) itself.
Antijoin( )
 The antijoin, written as R S where R and S are relations, is similar to
the natural join, but the result of an antijoin is only those tuples in R for
which there is no tuple in S that is equal on their common attribute
names.
 For an example consider the tables Employee and Dept and their
antijoin:
Anti Join (Example)
 SELECT * FROM employees
WHERE department_id NOT IN
(SELECT department_id FROM departments WHERE location_id = 1700)
ORDER BY last_name;
Self Join
 A self-join is joining a table to itself. This is best illustrated by an example.
 A query to find all pairings of two employees in the same country is desired.
If there were two separate tables for employees and a query which
requested employees in the first table having the same country as
employees in the second table, a normal join operation could be used to
find the answer table. However, all the employee information is contained
within a single large table.
Self Join (Example)
 joins in database
Query: Find the name of the sailor who
reserved boat 101.
Answer
Ad

More Related Content

What's hot (20)

SQL Views
SQL ViewsSQL Views
SQL Views
baabtra.com - No. 1 supplier of quality freshers
 
Database Triggers
Database TriggersDatabase Triggers
Database Triggers
Aliya Saldanha
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
Vigneshwaran Sankaran
 
Dbms 14: Relational Calculus
Dbms 14: Relational CalculusDbms 14: Relational Calculus
Dbms 14: Relational Calculus
Amiya9439793168
 
SQL commands
SQL commandsSQL commands
SQL commands
GirdharRatne
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
sinhacp
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
koolkampus
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
Anurag
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
Anusha sivakumar
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
Arun Sharma
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
GirdharRatne
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
Bharat Kalia
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
madhav bansal
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
Lakshman Basnet
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
Felipe Costa
 
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and AggregationDbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
BIT Durg
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
Sharad Dubey
 
DBMS: Types of keys
DBMS:  Types of keysDBMS:  Types of keys
DBMS: Types of keys
Bharati Ugale
 
Dbms 14: Relational Calculus
Dbms 14: Relational CalculusDbms 14: Relational Calculus
Dbms 14: Relational Calculus
Amiya9439793168
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
sinhacp
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
koolkampus
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
Anurag
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
Anusha sivakumar
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
Arun Sharma
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
GirdharRatne
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
Bharat Kalia
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
madhav bansal
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
Felipe Costa
 
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and AggregationDbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
BIT Durg
 

Similar to joins in database (20)

Relational Algebra-23-04-2023.pdf
Relational Algebra-23-04-2023.pdfRelational Algebra-23-04-2023.pdf
Relational Algebra-23-04-2023.pdf
VADAPALLYPRAVEENKUMA1
 
Unit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdfUnit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdf
ajajkhan16
 
relational algebra (joins)
relational algebra (joins)relational algebra (joins)
relational algebra (joins)
Nilt1234
 
Join
JoinJoin
Join
Kanchana Rani G
 
Joins
JoinsJoins
Joins
Yaswanth Babu Gummadivelli
 
dbmspresentation-161126155322.pptx
dbmspresentation-161126155322.pptxdbmspresentation-161126155322.pptx
dbmspresentation-161126155322.pptx
kumarkaushal17
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
VENNILAV6
 
Joins.ppt
Joins.pptJoins.ppt
Joins.ppt
UmangThakkar26
 
Mysql joins
Mysql joinsMysql joins
Mysql joins
baabtra.com - No. 1 supplier of quality freshers
 
Advance database system(part 8)
Advance database system(part 8)Advance database system(part 8)
Advance database system(part 8)
Abdullah Khosa
 
Relational Database management Systems unit-II
Relational Database management Systems unit-IIRelational Database management Systems unit-II
Relational Database management Systems unit-II
vanithar32
 
Joins in databases
Joins in databases Joins in databases
Joins in databases
CourseHunt
 
Presentation of Joins In Database
Presentation of Joins In DatabasePresentation of Joins In Database
Presentation of Joins In Database
Shashank Pathak
 
BCA_Semester-II-Discrete Mathematics_unit-ii_Relation and ordering
BCA_Semester-II-Discrete Mathematics_unit-ii_Relation and orderingBCA_Semester-II-Discrete Mathematics_unit-ii_Relation and ordering
BCA_Semester-II-Discrete Mathematics_unit-ii_Relation and ordering
Rai University
 
Day-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptxDay-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptx
uzmasulthana3
 
Join sql
Join sqlJoin sql
Join sql
Vikas Gupta
 
Sql join
Sql  joinSql  join
Sql join
Vikas Gupta
 
JOINS.pptx
JOINS.pptxJOINS.pptx
JOINS.pptx
ArunkumarT51
 
MS SQL SERVER: Joining Databases
MS SQL SERVER: Joining DatabasesMS SQL SERVER: Joining Databases
MS SQL SERVER: Joining Databases
sqlserver content
 
MS SQLSERVER:Joining Databases
MS SQLSERVER:Joining DatabasesMS SQLSERVER:Joining Databases
MS SQLSERVER:Joining Databases
sqlserver content
 
Ad

Recently uploaded (20)

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.
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
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
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
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
 
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
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
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
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
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
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
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
 
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
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
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
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Ad

joins in database

  • 1. Database Systems Types of Joins Syed Sarmad AliDatabase Management Systems 1 Lecture 12
  • 2. Today’s agenda(Joins in database) Natural Join Inner Join Equi Join Theta Join Semi Join Anti Join Cross Join Outer Join  Left Outer Join  Right Outer Join  Full Outer Join Self Join Database Management Systems 2
  • 3. Join  Join is a special form of cross product of two tables.  In Cartesian product we join a tuple of one table with the tuples of the second table. But in join there is a special requirement of relationship between tuples.  For example if there is a relation STUDENT and a relation BOOK then it may be required to know that how many books have been issued to any particular student. Now in this case the primary key of STUDENT that is stId is a foreign key in BOOK table through which the join can be made.
  • 5. Natural Join  Natural join ( ) is a binary operator that is written as (R S) where R and S are relations.  In particular, natural join allows the combination of relations that are associated by a foreign key.
  • 7. Semi Join ( ) and ( )  The left semijoin is joining similar to the natural join and written as R S where R and S are relation.  The result of this semijoin is only the set of all tuples in R for which there is a tuple in S that is equal on their common attribute names.  For an example consider the tables Employee and Dept and their semi join:
  • 8. Semi Join (Example) SELECT * FROM departments WHERE EXISTS (SELECT * FROM employees WHERE departments.department_id = employees.department_id AND employees.salary > 2500) ORDER BY department_name;
  • 9. 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) one retains the rows from (left, right, or both).
  • 10. Left Outer Join  The result of a left outer join (or simply left join) for table 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, the join will still return a row in the result—but with NULL in each column from B.  This means that a left outer join returns all the values from the left table, plus matched values from the right table (or NULL in case of no matching join predicate).  If the right table returns one row and the left table returns more than one matching row for it, the values in the right table will be repeated for each distinct row on the left table.
  • 12. Left Outer Join (Example)
  • 13. Right Outer Join  A right outer join (or right join) closely resembles a left outer join, except with the treatment of the tables reversed. 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 case of no matching join predicate).
  • 15. Right Outer Join (Example)
  • 16. Full Outer Join  Conceptually, a full outer join combines the effect of applying both left and right outer joins. Where records in the FULL OUTER JOINed 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).
  • 18. Full Outer Join (Example)
  • 19. Cartesian Product  In mathematics, it is a set of all pairs of elements (x, y) that can be constructed from given sets, X and Y, such that x belongs to X and y to Y.  It defines a relation that is the concatenation of every tuple of relation R with every tuple of relation S.
  • 21. Inner join  An inner join is the most common join operation used in applications and can be regarded as the default join-type.  Inner join creates a new result table by combining column values of two tables (A and B) based upon the join-predicate.  The query compares each row of A with each row of B to find all pairs of rows which satisfy the join-predicate. When the join- predicate is satisfied, column values for each matched pair of rows of A and B are combined into a result row.
  • 22. Equijoin  An equi-join, also known as an equijoin, is a specific type of comparator-based join, or theta join, that uses only equality comparisons in the join-predicate. Using other comparison operators (such as <) disqualifies a join as an equi-join.
  • 25. θ-join  Consider tables Car and Boat which list models of cars and boats and their respective prices.  Suppose a customer wants to buy a car and a boat, but she does not want to spend more money for the boat than for the car.  The θ-join on the relation CarPrice ≥ BoatPrice produces a table with all the possible options. If you are using a condition where the attributes are equal the like Price the condition may be specified as Price=Price or alternatively (Price) itself.
  • 26. Antijoin( )  The antijoin, written as R S where R and S are relations, is similar to the natural join, but the result of an antijoin is only those tuples in R for which there is no tuple in S that is equal on their common attribute names.  For an example consider the tables Employee and Dept and their antijoin:
  • 27. Anti Join (Example)  SELECT * FROM employees WHERE department_id NOT IN (SELECT department_id FROM departments WHERE location_id = 1700) ORDER BY last_name;
  • 28. Self Join  A self-join is joining a table to itself. This is best illustrated by an example.  A query to find all pairings of two employees in the same country is desired. If there were two separate tables for employees and a query which requested employees in the first table having the same country as employees in the second table, a normal join operation could be used to find the answer table. However, all the employee information is contained within a single large table.
  • 31. Query: Find the name of the sailor who reserved boat 101.