Skip to Main Content

Database Software

Using Join instead of Minus or not in operator for improving query performance

AkshsApr 29 2016 — edited May 3 2016

Having two table Tab_A and Tab_B.  And the requirement is my query should return the result ( Tab_A - Tab_b) i.2 10,20,30 .


Tab_A      Tab_B

10               40

20               50

30

40

50

Option -1:   (Using minus)                   

Select * from Tab_A

minus

Select * from Tab_B;


Option -2: (Using Not In)

Select * from Tab_A

where Tab_A.c1 not in ( Select Tab_B.c1 from Tab_B);


Option - 3 (Using Left outer Join to Improve the query performance)


Select Tab_A.c1 from Tab_A left outer join Tab_b

on (Tab_A.c1=Tab_B.c1)

where Tab_b.c1 is null;


Please check the detail explanation  :

Comments
Post Details
Added on Apr 29 2016
11 comments
121 views