SlideShare a Scribd company logo
1 of 16
Deepthi Rachumallu
SQL Joins
SQL joins are used to get data from two
or more tables bases on relationship
between some of the columns in tables.
In most of the cases we will use primary
key of first table and foreign key of
secondary table to get data from tables
Deepthi Rachumallu
Types of Joins
Deepthi Rachumallu
Tables for examples
EMPNO ENAME JOB MGR DEPTNO
111 Ramesh Analyst 444 10
222 Khilan Clerk 333 20
333 Kaushik Manager 111 10
444 Chaitali engineer 222 40
DEPTNO DNAME LOC
10 INVENTORY HYDERABAD
20 FINANCE BANGALORE
30 HR MUMBAI
Deepthi Rachumallu
INNER JOIN OR EQUIJOIN
clause is used to combine rows from two or more tables,
based on a common field between them.
INNER JOIN creates a new result table by combining
column values of two tables (table1 and table2) based
upon the join-condition.
Keyword used is INNER JOIN or simply JOIN.
Deepthi Rachumallu
INNER JOIN OR EQUIJOIN
Syntaxļƒ  SELECT table1.column1, table2.column2...
FROM table1 INNER JOIN table2 ON
table1.common_field = table2.common_field;
SELECT emp.ename,emp.job,dept.dname,dept.loc from EMPLOYYE emp
INNER JOIN DEPARTMENT dept ON emp.deptno = dept.deptno;
Deepthi Rachumallu
Resultā€¦ā€¦
ENAME JOB DNAME LOC
Ramesh Analyst INVENTORY HYDERABAD
Khilan Clerk FINANCE BANGALORE
Kaushik Manager INVENTORY HYDERABAD
Deepthi Rachumallu
Left Join/Left Outer Join
LEFT JOIN returns all rows from the left table (table1),
even if there are no matches in the right table(table2).
If there are no matches found in right table the result is
null in the right table.
Keyword used is LEFT JOIN.
Deepthi Rachumallu
Left Join Continuationā€¦
Syntax ļƒ  SELECT table1.column1, table2.column2...
FROM table1
LEFT JOIN table2 ON table1.common_field =
table2.common_field;
SELECT emp.ename,emp.job,dept.dname,dept.loc from EMPLOYYE emp
LEFT JOIN DEPARTMENT dept ON emp.deptno = dept.deptno;
OR
SELECT emp.ename,emp.job,dept.dname,dept.loc from EMPLOYYE emp ,
DEPARTMENT dept WHERE emp.deptno(+) = dept.deptno;
ENAME JOB DNAME LOC
Ramesh Analyst INVENTORY HYDERABAD
Khilan Clerk FINANCE BANGALORE
Kaushik Manager INVENTORY HYDERABAD
Chaitali engineer NULL NULL
Deepthi Rachumallu
Right Join/Right Outer Join
RIGHT JOIN returns all rows from the right table (table2),
even if there are no matches in the left table(table1).
If there are no matched found in let table the result is null
in the left table.
Keyword used is RIGHT JOIN.
Deepthi Rachumallu
Right Join Continuationā€¦
Syntax ļƒ  SELECT table1.column1, table2.column2...
FROM table1
RIGHT JOIN table2 ON table1.common_field =
table2.common_field;
SELECT emp.ename,emp.job,dept.dname,dept.loc from EMPLOYYE emp
RIGHT JOIN DEPARTMENT dept ON emp.deptno = dept.deptno;
OR
SELECT emp.ename,emp.job,dept.dname,dept.loc from EMPLOYYE emp,
DEPARTMENT dept WHERE emp.deptno = dept.deptno(+);
ENAME JOB DNAME LOC
Ramesh Analyst INVENTORY HYDERABAD
Khilan Clerk FINANCE BANGALORE
Kaushik Manager INVENTORY HYDERABAD
NULL NULL HR MUMBAI
Deepthi Rachumallu
Full Join
The SQL FULL JOIN combines the results of both left and
right outer joins.
The joined table will contain all records from both tables,
and fill in NULLs for missing matches on either side.
Keyword used is FULL JOIN. In some data bases it is also
known as FULL OUTER JOIN.
Deepthi Rachumallu
Full Join Continuationā€¦
Syntax ļƒ  SELECT table1.column1, table2.column2...
FROM table1
FULL JOIN table2 ON table1.common_field =
table2.common_field;
SELECT emp.ename,emp.job,dept.dname,dept.loc from EMPLOYYE emp
FULL JOIN DEPARTMENT dept ON emp.deptno = dept.deptno;
ENAME JOB DNAME LOC
Ramesh Analyst INVENTORY HYDERABAD
Khilan Clerk FINANCE BANGALORE
Kaushik Manager INVENTORY HYDERABAD
NULL NULL HR MUMBAI
Chaitali engineer NULL NULL
Deepthi Rachumallu
Self Join
SELF JOIN is used to join a table to itself as if the table
were two tables
Syntax ļƒ  SELECT a.column_name, b.column_name... FROM
table1 a, table1 b WHERE a.common_field = b.common_field;
Deepthi Rachumallu
Self Join Continuationā€¦.
SELECT emp1.ename, emp1.job, emp2.ename as manager
FROM EMPLOYEE emp1, EMPLOYEE emp2 where emp1.mgr =
emp2.empno;
ENAME JOB MANAGER
Ramesh Analyst Chaitali
Khilan Clerk Kaushik
Kaushik Manager Ramesh
Chaitali engineer Khilan
Deepthi Rachumallu
Deepthi Rachumallu

More Related Content

What's hot (20)

SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
Ā 
Sql operator
Sql operatorSql operator
Sql operator
Ā 
SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
Ā 
SQL commands
SQL commandsSQL commands
SQL commands
Ā 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
Ā 
Triggers
TriggersTriggers
Triggers
Ā 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
Ā 
SQL Join Basic
SQL Join BasicSQL Join Basic
SQL Join Basic
Ā 
Join
JoinJoin
Join
Ā 
Subqueries
SubqueriesSubqueries
Subqueries
Ā 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
Ā 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
Ā 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
Ā 
Relational model
Relational modelRelational model
Relational model
Ā 
Mysql
MysqlMysql
Mysql
Ā 
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
Ā 
Aggregate function
Aggregate functionAggregate function
Aggregate function
Ā 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Ā 
MS Sql Server: Joining Databases
MS Sql Server: Joining DatabasesMS Sql Server: Joining Databases
MS Sql Server: Joining Databases
Ā 
set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
Ā 

Viewers also liked (20)

SQL Joins
SQL JoinsSQL Joins
SQL Joins
Ā 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
Ā 
Sql joins
Sql joinsSql joins
Sql joins
Ā 
Semi join
Semi joinSemi join
Semi join
Ā 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
Ā 
Sql server select queries ppt 18
Sql server select queries ppt 18Sql server select queries ppt 18
Sql server select queries ppt 18
Ā 
Datastage Introduction To Data Warehousing
Datastage Introduction To Data WarehousingDatastage Introduction To Data Warehousing
Datastage Introduction To Data Warehousing
Ā 
MySQL JOIN & UNION
MySQL JOIN & UNIONMySQL JOIN & UNION
MySQL JOIN & UNION
Ā 
SQL DDL
SQL DDLSQL DDL
SQL DDL
Ā 
HRIS
HRISHRIS
HRIS
Ā 
Data definition language (ddl)
Data definition language (ddl)Data definition language (ddl)
Data definition language (ddl)
Ā 
History of C/C++ Language
History of C/C++ LanguageHistory of C/C++ Language
History of C/C++ Language
Ā 
Capturing Data Requirements
Capturing Data RequirementsCapturing Data Requirements
Capturing Data Requirements
Ā 
C++ history session 00 history
C++ history session 00   historyC++ history session 00   history
C++ history session 00 history
Ā 
C/C++ History in few slides
C/C++ History in few slides C/C++ History in few slides
C/C++ History in few slides
Ā 
History of c++
History of c++ History of c++
History of c++
Ā 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
Ā 
153 Oracle dba interview questions
153 Oracle dba interview questions153 Oracle dba interview questions
153 Oracle dba interview questions
Ā 
C++ language
C++ languageC++ language
C++ language
Ā 
Oracle Complete Interview Questions
Oracle Complete Interview QuestionsOracle Complete Interview Questions
Oracle Complete Interview Questions
Ā 

Similar to Sql joins inner join self join outer joins

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 analysisSanSan149
Ā 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQLPooja Dixit
Ā 
MS SQL SERVER: Joining Databases
MS SQL SERVER: Joining DatabasesMS SQL SERVER: Joining Databases
MS SQL SERVER: Joining Databasessqlserver content
Ā 
MS SQLSERVER:Joining Databases
MS SQLSERVER:Joining DatabasesMS SQLSERVER:Joining Databases
MS SQLSERVER:Joining Databasessqlserver content
Ā 
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 JoinSouma Maiti
Ā 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)Ishucs
Ā 
Lab4 join - all types listed
Lab4   join - all types listedLab4   join - all types listed
Lab4 join - all types listedBalqees Al.Mubarak
Ā 
Assignment 4
Assignment 4Assignment 4
Assignment 4SneaK3
Ā 
Day-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptxDay-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptxuzmasulthana3
Ā 
Presentation of Joins In Database
Presentation of Joins In DatabasePresentation of Joins In Database
Presentation of Joins In DatabaseShashank Pathak
Ā 
Joining
JoiningJoining
JoiningAbrar ali
Ā 

Similar to Sql joins inner join self join outer joins (20)

types of SQL Joins
 types of SQL Joins types of SQL Joins
types of SQL Joins
Ā 
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
Ā 
V19 join method-c
V19 join method-cV19 join method-c
V19 join method-c
Ā 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
Ā 
MS SQL SERVER: Joining Databases
MS SQL SERVER: Joining DatabasesMS SQL SERVER: Joining Databases
MS SQL SERVER: Joining Databases
Ā 
MS SQLSERVER:Joining Databases
MS SQLSERVER:Joining DatabasesMS SQLSERVER:Joining Databases
MS SQLSERVER:Joining Databases
Ā 
JOINS.pptx
JOINS.pptxJOINS.pptx
JOINS.pptx
Ā 
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
Ā 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
Ā 
Lab4 join - all types listed
Lab4   join - all types listedLab4   join - all types listed
Lab4 join - all types listed
Ā 
Assignment 4
Assignment 4Assignment 4
Assignment 4
Ā 
Sql joins
Sql joinsSql joins
Sql joins
Ā 
database .pptx
database .pptxdatabase .pptx
database .pptx
Ā 
Les04
Les04Les04
Les04
Ā 
Joins
JoinsJoins
Joins
Ā 
Day-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptxDay-2 SQL Theory_V1.pptx
Day-2 SQL Theory_V1.pptx
Ā 
Presentation of Joins In Database
Presentation of Joins In DatabasePresentation of Joins In Database
Presentation of Joins In Database
Ā 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
Ā 
App C
App CApp C
App C
Ā 
Joining
JoiningJoining
Joining
Ā 

Recently uploaded

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
Ā 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
Ā 
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
Ā 
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
Ā 
18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdfssuser54595a
Ā 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
Ā 
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
Ā 
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
Ā 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
Ā 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
Ā 
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
Ā 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
Ā 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
Ā 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
Ā 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
Ā 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
Ā 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
Ā 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at šŸ”9953056974šŸ”
Model Call Girl in Bikash Puri  Delhi reach out to us at šŸ”9953056974šŸ”Model Call Girl in Bikash Puri  Delhi reach out to us at šŸ”9953056974šŸ”
Model Call Girl in Bikash Puri Delhi reach out to us at šŸ”9953056974šŸ”
Ā 
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
Ā 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
Ā 
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
Ā 
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
Ā 
18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf
Ā 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Ā 
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
Ā 
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
Ā 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
Ā 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
Ā 
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
Ā 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
Ā 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
Ā 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
Ā 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
Ā 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
Ā 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
Ā 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
Ā 

Sql joins inner join self join outer joins

  • 2. SQL Joins SQL joins are used to get data from two or more tables bases on relationship between some of the columns in tables. In most of the cases we will use primary key of first table and foreign key of secondary table to get data from tables Deepthi Rachumallu
  • 4. Tables for examples EMPNO ENAME JOB MGR DEPTNO 111 Ramesh Analyst 444 10 222 Khilan Clerk 333 20 333 Kaushik Manager 111 10 444 Chaitali engineer 222 40 DEPTNO DNAME LOC 10 INVENTORY HYDERABAD 20 FINANCE BANGALORE 30 HR MUMBAI Deepthi Rachumallu
  • 5. INNER JOIN OR EQUIJOIN clause is used to combine rows from two or more tables, based on a common field between them. INNER JOIN creates a new result table by combining column values of two tables (table1 and table2) based upon the join-condition. Keyword used is INNER JOIN or simply JOIN. Deepthi Rachumallu
  • 6. INNER JOIN OR EQUIJOIN Syntaxļƒ  SELECT table1.column1, table2.column2... FROM table1 INNER JOIN table2 ON table1.common_field = table2.common_field; SELECT emp.ename,emp.job,dept.dname,dept.loc from EMPLOYYE emp INNER JOIN DEPARTMENT dept ON emp.deptno = dept.deptno; Deepthi Rachumallu
  • 7. Resultā€¦ā€¦ ENAME JOB DNAME LOC Ramesh Analyst INVENTORY HYDERABAD Khilan Clerk FINANCE BANGALORE Kaushik Manager INVENTORY HYDERABAD Deepthi Rachumallu
  • 8. Left Join/Left Outer Join LEFT JOIN returns all rows from the left table (table1), even if there are no matches in the right table(table2). If there are no matches found in right table the result is null in the right table. Keyword used is LEFT JOIN. Deepthi Rachumallu
  • 9. Left Join Continuationā€¦ Syntax ļƒ  SELECT table1.column1, table2.column2... FROM table1 LEFT JOIN table2 ON table1.common_field = table2.common_field; SELECT emp.ename,emp.job,dept.dname,dept.loc from EMPLOYYE emp LEFT JOIN DEPARTMENT dept ON emp.deptno = dept.deptno; OR SELECT emp.ename,emp.job,dept.dname,dept.loc from EMPLOYYE emp , DEPARTMENT dept WHERE emp.deptno(+) = dept.deptno; ENAME JOB DNAME LOC Ramesh Analyst INVENTORY HYDERABAD Khilan Clerk FINANCE BANGALORE Kaushik Manager INVENTORY HYDERABAD Chaitali engineer NULL NULL Deepthi Rachumallu
  • 10. Right Join/Right Outer Join RIGHT JOIN returns all rows from the right table (table2), even if there are no matches in the left table(table1). If there are no matched found in let table the result is null in the left table. Keyword used is RIGHT JOIN. Deepthi Rachumallu
  • 11. Right Join Continuationā€¦ Syntax ļƒ  SELECT table1.column1, table2.column2... FROM table1 RIGHT JOIN table2 ON table1.common_field = table2.common_field; SELECT emp.ename,emp.job,dept.dname,dept.loc from EMPLOYYE emp RIGHT JOIN DEPARTMENT dept ON emp.deptno = dept.deptno; OR SELECT emp.ename,emp.job,dept.dname,dept.loc from EMPLOYYE emp, DEPARTMENT dept WHERE emp.deptno = dept.deptno(+); ENAME JOB DNAME LOC Ramesh Analyst INVENTORY HYDERABAD Khilan Clerk FINANCE BANGALORE Kaushik Manager INVENTORY HYDERABAD NULL NULL HR MUMBAI Deepthi Rachumallu
  • 12. Full Join The SQL FULL JOIN combines the results of both left and right outer joins. The joined table will contain all records from both tables, and fill in NULLs for missing matches on either side. Keyword used is FULL JOIN. In some data bases it is also known as FULL OUTER JOIN. Deepthi Rachumallu
  • 13. Full Join Continuationā€¦ Syntax ļƒ  SELECT table1.column1, table2.column2... FROM table1 FULL JOIN table2 ON table1.common_field = table2.common_field; SELECT emp.ename,emp.job,dept.dname,dept.loc from EMPLOYYE emp FULL JOIN DEPARTMENT dept ON emp.deptno = dept.deptno; ENAME JOB DNAME LOC Ramesh Analyst INVENTORY HYDERABAD Khilan Clerk FINANCE BANGALORE Kaushik Manager INVENTORY HYDERABAD NULL NULL HR MUMBAI Chaitali engineer NULL NULL Deepthi Rachumallu
  • 14. Self Join SELF JOIN is used to join a table to itself as if the table were two tables Syntax ļƒ  SELECT a.column_name, b.column_name... FROM table1 a, table1 b WHERE a.common_field = b.common_field; Deepthi Rachumallu
  • 15. Self Join Continuationā€¦. SELECT emp1.ename, emp1.job, emp2.ename as manager FROM EMPLOYEE emp1, EMPLOYEE emp2 where emp1.mgr = emp2.empno; ENAME JOB MANAGER Ramesh Analyst Chaitali Khilan Clerk Kaushik Kaushik Manager Ramesh Chaitali engineer Khilan Deepthi Rachumallu