SlideShare a Scribd company logo
1 of 15
Joins
Presented By: Ajay M. Patel
Computer Engineering Department
Institute of Diploma Studies
Nirma University
OBJECTIVES
 What mean by join?
 Types of joins
 Equi Joins
 Non-equi Joins
 Inner Joins
 Outer Joins
 Cross Joins
 Self Joins
2
Joins
3
 A join is a query that combines rows from two or more
tables, views, or materialized views.
 Oracle performs a join whenever multiple tables appear in
the query's FROM clause.
 The query's select list can select any columns from any of
these tables.
 If any two of these tables have a column name in
common, then you must qualify all references to these
columns throughout the query with table names to avoid
ambiguity.
 In addition to join conditions, the WHERE clause of a join
query can also contain other conditions that refer to
columns of only one table. These conditions can further
restrict the rows returned by the join query.
Types of Joins:
4
 Equi Joins
 Non-equi Joins
 Inner Joins
 Outer Joins
 Cross Joins
 Self Joins
Inner Joins
5
 An inner join (sometimes called a “Simple Join“ ,
& “Equi Join”) is a join of two or more tables that
returns only those rows that satisfy the join
condition.
 Generally equivalence operator “ = ” is used.
 This type of join can be used in situations where
selecting only those rows that have values in
common in the columns specified in WHERE
clause.
Inner Joins Example:
6
 List out employee name and its department
name.
 Answer:
 select ename,dname from emp,dept where
emp.deptno = dept.deptno;
 List out employee number, employee name ,
department number, department name, salary.
 Answer:
 select empno,ename,emp.deptno,dname,sal from
emp,dept where emp.deptno = dept.deptno;
Outer Joins
7
 An outer join extends the result of a simple join. An outer
join returns all rows that satisfy the join condition and also
returns some or all of those rows from one table for which
no rows from the other satisfy the join condition.
 To write a query that performs an outer join of tables A
and B and returns all rows from A (a left outer join), use
the LEFT [OUTER] JOIN syntax in the FROM clause, or
apply the outer join operator (+) to all columns of B in
the join condition in the WHERE clause. For all rows in A
that have no matching rows in B, Oracle returns null for
any select list expressions containing columns of B.
Outer Joins
8
 LEFT OUTER JOIN Example:
 List out employee number, employee name , department
number, department name, salary.
 Answer:
 select empno,ename,emp.deptno,dname,sal from
emp,dept where emp.deptno = dept.deptno(+);
Outer Joins
9
 To write a query that performs an outer join of tables A
and B and returns all rows from B (a right outer join), use
the RIGHT [OUTER] JOIN syntax in the FROM clause, or
apply the outer join operator (+) to all columns of A in the
join condition in the WHERE clause. For all rows in B that
have no matching rows in A, Oracle returns null for any
select list expressions containing columns of A.
 To write a query that performs an outer join and returns all
rows from A and B, extended with nulls if they do not
satisfy the join condition (a full outer join), use the FULL
[OUTER] JOIN syntax in the FROM clause.
Outer Joins
10
 RIGHT OUTER JOIN Example:
 List out employee number, employee name , department
number, department name, salary.
 Answer:
 select empno,ename,dept.deptno,dname,sal from
emp,dept where emp.deptno(+) = dept.deptno;
Cross Joins
11
 If two tables in a join query have no join condition, Oracle
returns their Cartesian product.
 Oracle combines each row of one table with each row of
the other.
 A Cartesian product always generates many rows and is
rarely useful.
 For example, the Cartesian product of two tables, each
with 100 rows, has 10,000 rows. Always include a join
condition unless you specifically need a Cartesian
product.
 Example,
 Display empno,ename,dname for all the employees.
 select empno,ename,dname from emp,dept;
Self Joins
12
 A self join is a join of a table to itself.
 This table appears twice in the FROM clause and is
followed by table aliases that qualify column names in the
join condition.
 To perform a self join, Oracle combines and returns rows
of the table that satisfy the join condition.
 Example,
 List out employee name and its manager name for all the
employees.
 select e.ename,m.ename "Manager Name" from emp e,
emp m where e.mno = m.empno;
Equi Joins
13
 An equi join is a join with a join condition
containing an equality operator.
 An equi join combines rows that have equivalent
values for the specified columns.
 Like deptno column in emp table and dept table.
Non-equi Joins
14
 The join which uses comparison operation other
than ‘=’ while defining their joining criteria are
called non-equi joins.
 Since this join can result in large number of rows,
it is advisable to make a non-equi join in
combination with a selection criteria to reduce the
rows to a manageable range.
 We can use “Between”, “Like”, … operators for
comparison.
Thank You

More Related Content

Similar to Joins.ppt (20)

Assignment 4
Assignment 4Assignment 4
Assignment 4
 
e computer notes - From multiple tables
e computer notes - From multiple tablese computer notes - From multiple tables
e computer notes - From multiple tables
 
SQL report
SQL reportSQL report
SQL report
 
App C
App CApp C
App C
 
Bt0075 rdbms with mysql 2
Bt0075 rdbms with mysql 2Bt0075 rdbms with mysql 2
Bt0075 rdbms with mysql 2
 
Mysql joins
Mysql joinsMysql joins
Mysql joins
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
 
New Dynamic Array Functions. Excel Tutorial
New Dynamic Array Functions. Excel TutorialNew Dynamic Array Functions. Excel Tutorial
New Dynamic Array Functions. Excel Tutorial
 
Les06
Les06Les06
Les06
 
Ms excel
Ms excelMs excel
Ms excel
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
Displaying data from multiple tables
Displaying data from multiple tablesDisplaying data from multiple tables
Displaying data from multiple tables
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
 
Module03
Module03Module03
Module03
 
Sql slid
Sql slidSql slid
Sql slid
 
Sql joins
Sql joinsSql joins
Sql joins
 
1 introduction to my sql
1 introduction to my sql1 introduction to my sql
1 introduction to my sql
 
MULTIPLE TABLES
MULTIPLE TABLES MULTIPLE TABLES
MULTIPLE TABLES
 

Recently uploaded

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Recently uploaded (20)

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 

Joins.ppt

  • 1. Joins Presented By: Ajay M. Patel Computer Engineering Department Institute of Diploma Studies Nirma University
  • 2. OBJECTIVES  What mean by join?  Types of joins  Equi Joins  Non-equi Joins  Inner Joins  Outer Joins  Cross Joins  Self Joins 2
  • 3. Joins 3  A join is a query that combines rows from two or more tables, views, or materialized views.  Oracle performs a join whenever multiple tables appear in the query's FROM clause.  The query's select list can select any columns from any of these tables.  If any two of these tables have a column name in common, then you must qualify all references to these columns throughout the query with table names to avoid ambiguity.  In addition to join conditions, the WHERE clause of a join query can also contain other conditions that refer to columns of only one table. These conditions can further restrict the rows returned by the join query.
  • 4. Types of Joins: 4  Equi Joins  Non-equi Joins  Inner Joins  Outer Joins  Cross Joins  Self Joins
  • 5. Inner Joins 5  An inner join (sometimes called a “Simple Join“ , & “Equi Join”) is a join of two or more tables that returns only those rows that satisfy the join condition.  Generally equivalence operator “ = ” is used.  This type of join can be used in situations where selecting only those rows that have values in common in the columns specified in WHERE clause.
  • 6. Inner Joins Example: 6  List out employee name and its department name.  Answer:  select ename,dname from emp,dept where emp.deptno = dept.deptno;  List out employee number, employee name , department number, department name, salary.  Answer:  select empno,ename,emp.deptno,dname,sal from emp,dept where emp.deptno = dept.deptno;
  • 7. Outer Joins 7  An outer join extends the result of a simple join. An outer join returns all rows that satisfy the join condition and also returns some or all of those rows from one table for which no rows from the other satisfy the join condition.  To write a query that performs an outer join of tables A and B and returns all rows from A (a left outer join), use the LEFT [OUTER] JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of B in the join condition in the WHERE clause. For all rows in A that have no matching rows in B, Oracle returns null for any select list expressions containing columns of B.
  • 8. Outer Joins 8  LEFT OUTER JOIN Example:  List out employee number, employee name , department number, department name, salary.  Answer:  select empno,ename,emp.deptno,dname,sal from emp,dept where emp.deptno = dept.deptno(+);
  • 9. Outer Joins 9  To write a query that performs an outer join of tables A and B and returns all rows from B (a right outer join), use the RIGHT [OUTER] JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of A in the join condition in the WHERE clause. For all rows in B that have no matching rows in A, Oracle returns null for any select list expressions containing columns of A.  To write a query that performs an outer join and returns all rows from A and B, extended with nulls if they do not satisfy the join condition (a full outer join), use the FULL [OUTER] JOIN syntax in the FROM clause.
  • 10. Outer Joins 10  RIGHT OUTER JOIN Example:  List out employee number, employee name , department number, department name, salary.  Answer:  select empno,ename,dept.deptno,dname,sal from emp,dept where emp.deptno(+) = dept.deptno;
  • 11. Cross Joins 11  If two tables in a join query have no join condition, Oracle returns their Cartesian product.  Oracle combines each row of one table with each row of the other.  A Cartesian product always generates many rows and is rarely useful.  For example, the Cartesian product of two tables, each with 100 rows, has 10,000 rows. Always include a join condition unless you specifically need a Cartesian product.  Example,  Display empno,ename,dname for all the employees.  select empno,ename,dname from emp,dept;
  • 12. Self Joins 12  A self join is a join of a table to itself.  This table appears twice in the FROM clause and is followed by table aliases that qualify column names in the join condition.  To perform a self join, Oracle combines and returns rows of the table that satisfy the join condition.  Example,  List out employee name and its manager name for all the employees.  select e.ename,m.ename "Manager Name" from emp e, emp m where e.mno = m.empno;
  • 13. Equi Joins 13  An equi join is a join with a join condition containing an equality operator.  An equi join combines rows that have equivalent values for the specified columns.  Like deptno column in emp table and dept table.
  • 14. Non-equi Joins 14  The join which uses comparison operation other than ‘=’ while defining their joining criteria are called non-equi joins.  Since this join can result in large number of rows, it is advisable to make a non-equi join in combination with a selection criteria to reduce the rows to a manageable range.  We can use “Between”, “Like”, … operators for comparison.