You are on page 1of 19

JOINS

MERGE
For more details,
https://oracle-base.com/articles/9i/merge-statement

INSERT ALL
https://www.oracletutorial.com/oracle-basics/oracle-insert-all/

Unconditional INSERT ALL, use to insert multiple records We can specify conditions to insert the reco
ACID Properties
s
pecify conditions to insert the records into different tables It inserts the record wherever the first condition is being m
he first condition is being met
How Oracle compares each and every value of T1 with T2

Table T1 Table T2
ID ID
1 NULL itration 1 itration 2 itration 3
2 3 0 1=null 0 2=null 0 3=null
3 4 0 1=3 0 2=3 1 3=3
NULL 5 0 1=4 0 2=4 0 3=4
3 5 0 1=5 0 2=5 0 3=5
4 0 1=5 0 2=5 0 3=5

Query itration 4 itration 5 itration 6


SELECT * null is null 1 0 null=null 0 3=null 0 4=null
FROM T1 0 null=3 1 3=3 0 4=3
INNER JOIN T2 0 null=4 0 3=4 1 4=4
ON T1.ID = T2.ID; 0 null=5 0 3=5 0 4=5
0 null=5 0 3=5 0 4=5
Another Example

T1 T2 JOIN COUNT
1 1 IJ "11"
1 1 ROJ "11+2=13"
2 1 LOJ "11+4=15"
2 2 FOJ "11+2+4=17"
3 3
NULL 3
NULL 3
7 NULL
8 5
Table1 Table2 LEFT OUTER JOIN
ID Name ID Name Table1 Table2
1 Sagar NULL Nayan 3 Viram 3 Kalpesh
2 Azim 3 Kalpesh 3 Chetan 3 Kalpesh
3 Viram 4 Hemant 4 Raam 4 Hemant
NULL Yogesh 5 Ajay 1 Sagar NULL NULL
3 Chetan 5 Junaid 2 Azim NULL NULL
4 Raam NULL Yogesh NULL NULL

RIGHT OUTER JOIN


Table1 Table2
Inner JOIN 3 Viram 3 Kalpesh
Table1 Table2 3 Chetan 3 Kalpesh
3 Viram 3 Kalpesh 4 Raam 4 Hemant
3 Chetan 3 Kalpesh NULL NULL NULL Nayan
4 Raam 4 Hemant NULL NULL 5 Ajay
NULL NULL 5 Junaid
Ex. 2
T1 T2
1 1
1 1
NULL 1
NULL
FULL OUTER JOIN
Inner JOIN Table1 Table2
3 Viram 3 Kalpesh
3 Chetan 3 Kalpesh Inner JOIN
Non matching
rown from LEFT 4 Raam 4 Hemant
Table 1 Sagar NULL NULL
Non matching
2 Azim NULL NULL rown from LEFT
NULL Yogesh NULL NULL Table
NULL NULL NULL Nayan
Non matching
NULL NULL 5 Ajay rows from RIGHT
Inner JOIN NULL NULL 5 Junaid Table

Non matching
rows from
RIGHT Table CROSS JOIN
1 Sagar NULL Nayan
2 Azim NULL Nayan
3 Viram NULL Nayan
NULL Yogesh NULL Nayan
3 Chetan NULL Nayan
4 Raam NULL Nayan
1 Sagar 3 Kalpesh
2 Azim 3 Kalpesh
3 Viram 3 Kalpesh
NULL Yogesh 3 Kalpesh
3 Chetan 3 Kalpesh
4 Raam 3 Kalpesh
1 Sagar 4 Hemant
2 Azim 4 Hemant
3 Viram 4 Hemant
NULL Yogesh 4 Hemant
3 Chetan 4 Hemant
4 Raam 4 Hemant
1 Sagar 5 Ajay
2 Azim 5 Ajay
3 Viram 5 Ajay
NULL Yogesh 5 Ajay
3 Chetan 5 Ajay
4 Raam 5 Ajay
1 Sagar 5 Junaid
2 Azim 5 Junaid
3 Viram 5 Junaid
NULL Yogesh 5 Junaid
3 Chetan 5 Junaid
4 Raam 5 Junaid
1

4
5

8
9

10
11

You might also like