SlideShare a Scribd company logo
1 of 37
JOINS IN SQL
-VARSHA KUMARI
content
 Joins:
 Cartesian Product
 Natural Join
 Equi Join
 Self Join
 Inner Join
 outer Join(Left, Right, Full)
JOINS
 A JOIN combines together information from two or
more tables into one result set.
 The records from the table are fetched based on
some values that are common to each.
 It can also specifies some condition while
retrieving the data.
 Join = cross product + some condition
Cartesian product
 Before understanding JOINS in SQL we
should know about Cartesian Product.
 Also known as Cross Product.
Cartesian Product in sets(Mathematics)
 A = { 1, 2, 3} B = { a , b}
 A x B = { (1,a) , (2,a), (3,a), (1, b), (2,b) , (3,b) }
Cartesian product
 R1 R2
 R1 x R2
A B
2 E1
4 E2
5 E3
B C
E1 5
E5 7
A B B C
2 E1 E1 5
4 E2 E1 5
5 E3 E1 5
.. .. .. ..
Cartesian product
 R1 R2
 R1 x R2
A B
2 E1
4 E2
5 E3
B C
E1 5
E5 7
A B B C
2 E1 E1 5
4 E2 E1 5
5 E3 E1 5
2 E1 E5 7
4 E2 E5 7
5 E3 E5 7
Example : Consider two tables
Table creation
Cartesian product of two table
QUERY: select * from emp2,dept;
Cartesian Product :
 Cartesian Product is the all possible combinations
between applied table rows.
 Suppose two tables are T1 and T2
 T1 has r1 rows and c1 columns
 T2 has r2 rows and c2 columns
 Cartesian product of T1 and T2 will have:
 r1 * r2 rows and c1 + c2 columns.
Natural Join: Common columns in both the tables
must have same name.
After Natural Join :
 Select * from R1, R2
where R1.B=R2.B;
OR Select *
from R1 natural join R2;
=
A B
2 E1
4 E2
5 E3
B C
E1 5
E2 7
A B B C
2 E1 E1 5
4 E2 E1 5
5 E3 E1 5
2 E1 E2 7
4 E2 E2 7
5 E3 E2 7
A B C
2 E1 5
4 E2 7
Natural JOIN:
Select * from Emp2 natural join Dept;
- Behaves Same as Inner Join
- In Natural Join common attribute must have
same name in both the tables
Example:
 Select emp_name, loc from Emp2 natural join Dept
where loc= 'NEW YORK';
Equi Join
 R1 R2
 After Equi Join :
 Select *from R1,R2
 where R1.B=R2.C;
 or Select *from R1 join R2
 on R1.B=R2.C;
A B
2 E1
4 E2
5 E3
C D
E1 5
E2 7
A B C D
2 E1 E1 5
4 E2 E1 5
5 E3 E1 5
2 E1 E2 7
4 E2 E2 7
5 E3 E2 7
A B C D
2 E1 E1 5
4 E2 E2 7
Equi Join:
 Same as inner join , it uses only equality
comparison.
 Query : Select * from Emp2, dept where
emp2.deptno=dept.deptno;
Self Join
 A self Join is a type of Join which is used to join a
table to itself. In this join both the columns belongs
to the same table.
 Syntax :
 Select T1.column, T1.column from T1 A inner join T2 B on
A.column= B.column
Self Join
 R1
After Equi Join :
Select T.B
from R1 T, R1 S
where T.A=S.A
and T.B <> S.B;
A B
2 E1
2 E2
5 E3
A B A B
2 E1 2 E1
2 E2 2 E1
5 E3 2 E1
2 E1 2 E2
2 E2 2 E2
5 E3 2 E2
2 E1 5 E3
2 E2 5 E3
5 E3 5 E3
B
E2
E1
Select * from Emp2 A , Emp2 B
where A.Deptno = B.Deptno;
Inner Join
 Inner Join combines the rows retrieved from
multiple tables on the basis of common columns of
the tables.
 It takes that rows from the cartesian product table
where the join elements ( emp.deptno and
dept.deptno in the above query) matches fully
 Syntax:
 Select T1.column, T2.column from T1 inner join T2
on T1.column=T2.column
Inner Join
 R1 R2
 After Inner Join
=
A B
2 E1
4 E2
5 E3
B C
E1 5
E2 7
A B B C
2 E1 E1 5
4 E2 E1 5
5 E3 E1 5
2 E1 E2 7
4 E2 E2 7
5 E3 E2 7
A B B C
2 E1 E1 5
4 E2 E2 7
Select * from Emp2 inner join Dept on
Emp2.Deptno = Dept.Deptno
example
 Select * from Emp2 inner join Dept on
Emp2.Deptno = Dept.Deptno
where loc= 'NEW YORK';
Example:
 Select emp_name,loc from Emp2 inner join Dept
on Emp2.Deptno = Dept.Deptno where loc= 'NEW
YORK';
Left Outer Join
 Left outer Join takes that rows which are in inner
join output.
 And it also looks for the rows in the left table
which are not in the inner join output.
 The rows are added to the output with null in right
columns.
Left Join
 R1 R2
 After Left Join
=
A B
2 E1
4 E2
5 E3
B C
E1 5
E2 7
A B B C
2 E1 E1 5
4 E2 E1 5
5 E3 E1 5
2 E1 E2 7
4 E2 E2 7
5 E3 E2 7
A B B C
2 E1 E1 5
4 E2 E2 7
5 E3 NUL
L
NUL
L
Syntax:
 Select T1.column, T2.column from T1 left outer
join T2 on T1.column=T2.column
Eg. Select * from Emp2 left outer join Dept on
Emp2.Deptno = Dept.Deptno;
Right Outer Join
 Right outer Join takes that rows which are in inner
join output.
 And it also looks for the rows in the right table
which are not in the inner join output.
 The rows are added to the output with null in left
columns.
Right Join
 R1 R2
 After right Join
=
A B
2 E1
4 E2
5 E3
B C
E1 5
E5 7
A B B C
2 E1 E1 5
4 E2 E1 5
5 E3 E1 5
2 E1 E5 7
4 E2 E5 7
5 E3 E5 7
A B B C
2 E1 E1 5
NULL NULL E5 7
Syntax:
 Select T1.column, T2.column from T1 right outer
join T2 on T1.column=T2.column
Eg. Select * from Emp2 right outer join Dept on
Emp2.Deptno = Dept.Deptno;
Full Outer Join
 Full outer Join takes that rows which are in inner
join output.
 And it also looks for the rows in the left and also
right table which are not in the inner join output.
Full Join
 R1 R2
 After Full Join
=
A B
2 E1
4 E2
5 E3
B C
E1 5
E5 7
A B B C
2 E1 E1 5
4 E2 E1 5
5 E3 E1 5
2 E1 E5 7
4 E2 E5 7
5 E3 E5 7
A B B C
2 E1 E1 5
NULL NULL E5 7
4 E2 NULL NULL
5 E3 NULL NULL
Syntax:
 Select T1.column, T2.column from T1 full outer
join T2 on T1.column=T2.column
Eg. Select * from Emp2 full outer join Dept on
Emp2.Deptno = Dept.Deptno;
Consider two table
Student Faculty
S_id S_name course
1 Amit BCA
2 Ram Btech
3 Hardik BCA
4 Pawan BCA
5 Sumit Btech
6 Aman MCA
7 Hardik BCA
F_Id course Loc
F1 BCA AB 10
F2 Btech AB 1
F3 MTech AB1
 Cartesian product:
 Select * from Student, Faculty;
 Natural Join:
 Select * from Student natural join Faculty
 Equi join:
 Select * from student join Faculty on
Student.course=Faculty.course
 Self join:
 Select A.S_name from Student A, Student B where
A.S_id= B.S_id
 Inner Join:
 Select Student.S_name from Student inner join
Faculty on Student.course= Faculty.course where
Faculty.loc=‘AB10’
 Left Join:
 Select Student.S_name from Student left outer join
Faculty on Student.course= Faculty.course where
Faculty.loc=‘AB10’
 Right Join:
 Select Student.S_name from Student right outer join
Faculty on Student.course= Faculty.course where
Faculty.loc=‘AB10’

More Related Content

What's hot

What's hot (20)

Formula
FormulaFormula
Formula
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Mixed Number Notes For Web
Mixed Number Notes For WebMixed Number Notes For Web
Mixed Number Notes For Web
 
Python : basic operators
Python : basic operatorsPython : basic operators
Python : basic operators
 
Csc1100 lecture05 ch05
Csc1100 lecture05 ch05Csc1100 lecture05 ch05
Csc1100 lecture05 ch05
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Coper in C
Coper in CCoper in C
Coper in C
 
Unit i intro-operators
Unit   i intro-operatorsUnit   i intro-operators
Unit i intro-operators
 
Excle formula
Excle formulaExcle formula
Excle formula
 
programming fortran 77 Slide02
programming fortran 77 Slide02programming fortran 77 Slide02
programming fortran 77 Slide02
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Type Script 3.x - Was war. Was kommt!
Type Script 3.x - Was war. Was kommt!Type Script 3.x - Was war. Was kommt!
Type Script 3.x - Was war. Was kommt!
 
Final project
Final projectFinal project
Final project
 
Bis 345-final-exam-guide-set-1-new
Bis 345-final-exam-guide-set-1-newBis 345-final-exam-guide-set-1-new
Bis 345-final-exam-guide-set-1-new
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)
 
Python : Operators
Python : OperatorsPython : Operators
Python : Operators
 
Binary logic
Binary logicBinary logic
Binary logic
 
Learn about algorithm
Learn about algorithm Learn about algorithm
Learn about algorithm
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 

Similar to Joins

Internal tables
Internal tables Internal tables
Internal tables Jibu Jose
 
Using Lateral derived table in Informix database
Using Lateral derived table in Informix databaseUsing Lateral derived table in Informix database
Using Lateral derived table in Informix databaseAjay Gupte
 
Best SAP ABAP Training Institute with Placement in Pune | Aspire
Best SAP ABAP Training Institute with Placement in Pune | AspireBest SAP ABAP Training Institute with Placement in Pune | Aspire
Best SAP ABAP Training Institute with Placement in Pune | AspireAspire Techsoft Academy
 
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
 
Lesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdfLesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdfHasankaWijesinghe1
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manualNitesh Dubey
 
Sap internal
Sap   internalSap   internal
Sap internalkyashpal
 
Interactive spreadsheet basics[1]
Interactive spreadsheet basics[1]Interactive spreadsheet basics[1]
Interactive spreadsheet basics[1]ngoodfellow
 
Lecture 6 data structures and algorithms
Lecture 6 data structures and algorithmsLecture 6 data structures and algorithms
Lecture 6 data structures and algorithmsAakash deep Singhal
 
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And EngineersAnswers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And EngineersSheila Sinclair
 
LR parsing
LR parsingLR parsing
LR parsingichikaz3
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingR Islam
 
R-Data table Cheat Sheet
R-Data table Cheat SheetR-Data table Cheat Sheet
R-Data table Cheat SheetDr. Volkan OBAN
 

Similar to Joins (20)

Internal tables
Internal tables Internal tables
Internal tables
 
To excel or not?
To excel or not?To excel or not?
To excel or not?
 
Using Lateral derived table in Informix database
Using Lateral derived table in Informix databaseUsing Lateral derived table in Informix database
Using Lateral derived table in Informix database
 
Sql joins
Sql joinsSql joins
Sql joins
 
Bcsl 033 solve assignment
Bcsl 033 solve assignmentBcsl 033 solve assignment
Bcsl 033 solve assignment
 
Aspire it sap abap training
Aspire it   sap abap trainingAspire it   sap abap training
Aspire it sap abap training
 
Best SAP ABAP Training Institute with Placement in Pune | Aspire
Best SAP ABAP Training Institute with Placement in Pune | AspireBest SAP ABAP Training Institute with Placement in Pune | Aspire
Best SAP ABAP Training Institute with Placement in Pune | Aspire
 
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
 
Lesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdfLesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdf
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
 
Sap internal
Sap   internalSap   internal
Sap internal
 
Interactive spreadsheet basics[1]
Interactive spreadsheet basics[1]Interactive spreadsheet basics[1]
Interactive spreadsheet basics[1]
 
Lecture 6 data structures and algorithms
Lecture 6 data structures and algorithmsLecture 6 data structures and algorithms
Lecture 6 data structures and algorithms
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
SQL JOINS- Reena P V
SQL JOINS- Reena P VSQL JOINS- Reena P V
SQL JOINS- Reena P V
 
5.stack
5.stack5.stack
5.stack
 
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And EngineersAnswers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
Answers To Selected Exercises For Fortran 90 95 For Scientists And Engineers
 
LR parsing
LR parsingLR parsing
LR parsing
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
 
R-Data table Cheat Sheet
R-Data table Cheat SheetR-Data table Cheat Sheet
R-Data table Cheat Sheet
 

More from VARSHAKUMARI49

28,29. procedures subprocedure,type checking functions in VBScript
28,29. procedures  subprocedure,type checking functions in VBScript28,29. procedures  subprocedure,type checking functions in VBScript
28,29. procedures subprocedure,type checking functions in VBScriptVARSHAKUMARI49
 
30,31,32,33. decision and loop statements in vbscript
30,31,32,33. decision and loop statements in vbscript30,31,32,33. decision and loop statements in vbscript
30,31,32,33. decision and loop statements in vbscriptVARSHAKUMARI49
 
27. mathematical, date and time functions in VB Script
27. mathematical, date and time  functions in VB Script27. mathematical, date and time  functions in VB Script
27. mathematical, date and time functions in VB ScriptVARSHAKUMARI49
 
Introduction to web technology
Introduction to web technologyIntroduction to web technology
Introduction to web technologyVARSHAKUMARI49
 
Database normalization
Database normalizationDatabase normalization
Database normalizationVARSHAKUMARI49
 
Register counters.readonly
Register counters.readonlyRegister counters.readonly
Register counters.readonlyVARSHAKUMARI49
 

More from VARSHAKUMARI49 (17)

28,29. procedures subprocedure,type checking functions in VBScript
28,29. procedures  subprocedure,type checking functions in VBScript28,29. procedures  subprocedure,type checking functions in VBScript
28,29. procedures subprocedure,type checking functions in VBScript
 
30,31,32,33. decision and loop statements in vbscript
30,31,32,33. decision and loop statements in vbscript30,31,32,33. decision and loop statements in vbscript
30,31,32,33. decision and loop statements in vbscript
 
27. mathematical, date and time functions in VB Script
27. mathematical, date and time  functions in VB Script27. mathematical, date and time  functions in VB Script
27. mathematical, date and time functions in VB Script
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
 
Html
HtmlHtml
Html
 
Introduction to web technology
Introduction to web technologyIntroduction to web technology
Introduction to web technology
 
Database normalization
Database normalizationDatabase normalization
Database normalization
 
Sub queries
Sub queriesSub queries
Sub queries
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
Vbscript
VbscriptVbscript
Vbscript
 
Css module1
Css module1Css module1
Css module1
 
Js mod1
Js mod1Js mod1
Js mod1
 
Css mod1
Css mod1Css mod1
Css mod1
 
Html mod1
Html mod1Html mod1
Html mod1
 
Register counters.readonly
Register counters.readonlyRegister counters.readonly
Register counters.readonly
 
Sorting.ppt read only
Sorting.ppt read onlySorting.ppt read only
Sorting.ppt read only
 
Hashing
HashingHashing
Hashing
 

Recently uploaded

Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Recently uploaded (20)

Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 

Joins

  • 2. content  Joins:  Cartesian Product  Natural Join  Equi Join  Self Join  Inner Join  outer Join(Left, Right, Full)
  • 3. JOINS  A JOIN combines together information from two or more tables into one result set.  The records from the table are fetched based on some values that are common to each.  It can also specifies some condition while retrieving the data.  Join = cross product + some condition
  • 4. Cartesian product  Before understanding JOINS in SQL we should know about Cartesian Product.  Also known as Cross Product.
  • 5. Cartesian Product in sets(Mathematics)  A = { 1, 2, 3} B = { a , b}  A x B = { (1,a) , (2,a), (3,a), (1, b), (2,b) , (3,b) }
  • 6. Cartesian product  R1 R2  R1 x R2 A B 2 E1 4 E2 5 E3 B C E1 5 E5 7 A B B C 2 E1 E1 5 4 E2 E1 5 5 E3 E1 5 .. .. .. ..
  • 7. Cartesian product  R1 R2  R1 x R2 A B 2 E1 4 E2 5 E3 B C E1 5 E5 7 A B B C 2 E1 E1 5 4 E2 E1 5 5 E3 E1 5 2 E1 E5 7 4 E2 E5 7 5 E3 E5 7
  • 8. Example : Consider two tables
  • 10. Cartesian product of two table QUERY: select * from emp2,dept;
  • 11.
  • 12. Cartesian Product :  Cartesian Product is the all possible combinations between applied table rows.  Suppose two tables are T1 and T2  T1 has r1 rows and c1 columns  T2 has r2 rows and c2 columns  Cartesian product of T1 and T2 will have:  r1 * r2 rows and c1 + c2 columns.
  • 13. Natural Join: Common columns in both the tables must have same name. After Natural Join :  Select * from R1, R2 where R1.B=R2.B; OR Select * from R1 natural join R2; = A B 2 E1 4 E2 5 E3 B C E1 5 E2 7 A B B C 2 E1 E1 5 4 E2 E1 5 5 E3 E1 5 2 E1 E2 7 4 E2 E2 7 5 E3 E2 7 A B C 2 E1 5 4 E2 7
  • 14. Natural JOIN: Select * from Emp2 natural join Dept; - Behaves Same as Inner Join - In Natural Join common attribute must have same name in both the tables
  • 15. Example:  Select emp_name, loc from Emp2 natural join Dept where loc= 'NEW YORK';
  • 16. Equi Join  R1 R2  After Equi Join :  Select *from R1,R2  where R1.B=R2.C;  or Select *from R1 join R2  on R1.B=R2.C; A B 2 E1 4 E2 5 E3 C D E1 5 E2 7 A B C D 2 E1 E1 5 4 E2 E1 5 5 E3 E1 5 2 E1 E2 7 4 E2 E2 7 5 E3 E2 7 A B C D 2 E1 E1 5 4 E2 E2 7
  • 17. Equi Join:  Same as inner join , it uses only equality comparison.  Query : Select * from Emp2, dept where emp2.deptno=dept.deptno;
  • 18. Self Join  A self Join is a type of Join which is used to join a table to itself. In this join both the columns belongs to the same table.  Syntax :  Select T1.column, T1.column from T1 A inner join T2 B on A.column= B.column
  • 19. Self Join  R1 After Equi Join : Select T.B from R1 T, R1 S where T.A=S.A and T.B <> S.B; A B 2 E1 2 E2 5 E3 A B A B 2 E1 2 E1 2 E2 2 E1 5 E3 2 E1 2 E1 2 E2 2 E2 2 E2 5 E3 2 E2 2 E1 5 E3 2 E2 5 E3 5 E3 5 E3 B E2 E1
  • 20. Select * from Emp2 A , Emp2 B where A.Deptno = B.Deptno;
  • 21. Inner Join  Inner Join combines the rows retrieved from multiple tables on the basis of common columns of the tables.  It takes that rows from the cartesian product table where the join elements ( emp.deptno and dept.deptno in the above query) matches fully  Syntax:  Select T1.column, T2.column from T1 inner join T2 on T1.column=T2.column
  • 22. Inner Join  R1 R2  After Inner Join = A B 2 E1 4 E2 5 E3 B C E1 5 E2 7 A B B C 2 E1 E1 5 4 E2 E1 5 5 E3 E1 5 2 E1 E2 7 4 E2 E2 7 5 E3 E2 7 A B B C 2 E1 E1 5 4 E2 E2 7
  • 23. Select * from Emp2 inner join Dept on Emp2.Deptno = Dept.Deptno
  • 24. example  Select * from Emp2 inner join Dept on Emp2.Deptno = Dept.Deptno where loc= 'NEW YORK';
  • 25. Example:  Select emp_name,loc from Emp2 inner join Dept on Emp2.Deptno = Dept.Deptno where loc= 'NEW YORK';
  • 26. Left Outer Join  Left outer Join takes that rows which are in inner join output.  And it also looks for the rows in the left table which are not in the inner join output.  The rows are added to the output with null in right columns.
  • 27. Left Join  R1 R2  After Left Join = A B 2 E1 4 E2 5 E3 B C E1 5 E2 7 A B B C 2 E1 E1 5 4 E2 E1 5 5 E3 E1 5 2 E1 E2 7 4 E2 E2 7 5 E3 E2 7 A B B C 2 E1 E1 5 4 E2 E2 7 5 E3 NUL L NUL L
  • 28. Syntax:  Select T1.column, T2.column from T1 left outer join T2 on T1.column=T2.column Eg. Select * from Emp2 left outer join Dept on Emp2.Deptno = Dept.Deptno;
  • 29. Right Outer Join  Right outer Join takes that rows which are in inner join output.  And it also looks for the rows in the right table which are not in the inner join output.  The rows are added to the output with null in left columns.
  • 30. Right Join  R1 R2  After right Join = A B 2 E1 4 E2 5 E3 B C E1 5 E5 7 A B B C 2 E1 E1 5 4 E2 E1 5 5 E3 E1 5 2 E1 E5 7 4 E2 E5 7 5 E3 E5 7 A B B C 2 E1 E1 5 NULL NULL E5 7
  • 31. Syntax:  Select T1.column, T2.column from T1 right outer join T2 on T1.column=T2.column Eg. Select * from Emp2 right outer join Dept on Emp2.Deptno = Dept.Deptno;
  • 32. Full Outer Join  Full outer Join takes that rows which are in inner join output.  And it also looks for the rows in the left and also right table which are not in the inner join output.
  • 33. Full Join  R1 R2  After Full Join = A B 2 E1 4 E2 5 E3 B C E1 5 E5 7 A B B C 2 E1 E1 5 4 E2 E1 5 5 E3 E1 5 2 E1 E5 7 4 E2 E5 7 5 E3 E5 7 A B B C 2 E1 E1 5 NULL NULL E5 7 4 E2 NULL NULL 5 E3 NULL NULL
  • 34. Syntax:  Select T1.column, T2.column from T1 full outer join T2 on T1.column=T2.column Eg. Select * from Emp2 full outer join Dept on Emp2.Deptno = Dept.Deptno;
  • 35. Consider two table Student Faculty S_id S_name course 1 Amit BCA 2 Ram Btech 3 Hardik BCA 4 Pawan BCA 5 Sumit Btech 6 Aman MCA 7 Hardik BCA F_Id course Loc F1 BCA AB 10 F2 Btech AB 1 F3 MTech AB1
  • 36.  Cartesian product:  Select * from Student, Faculty;  Natural Join:  Select * from Student natural join Faculty  Equi join:  Select * from student join Faculty on Student.course=Faculty.course  Self join:  Select A.S_name from Student A, Student B where A.S_id= B.S_id
  • 37.  Inner Join:  Select Student.S_name from Student inner join Faculty on Student.course= Faculty.course where Faculty.loc=‘AB10’  Left Join:  Select Student.S_name from Student left outer join Faculty on Student.course= Faculty.course where Faculty.loc=‘AB10’  Right Join:  Select Student.S_name from Student right outer join Faculty on Student.course= Faculty.course where Faculty.loc=‘AB10’