Tuesday, June 24, 2008

Exists vs. In

The following two queries produce the same result. Using Exists can be a lot faster since often only an index needs to be checked.
Select Table_Name
From User_Tables
Where Table_Name In (Select Table_Name
From User_Constraints
)
;

Select Table_Name
From User_Tables Ut
Where Exists (Select 1
From User_Constraints Uc
Where Ut.Table_Name = Uc.Table_Name
)
;
See Oracle documentation for further detail:
Exists
Correlated Subquery

No comments:

Post a Comment