apache > db
Apache DB Project
 
Font size:      

DISTINCT Elimination in IN, ANY, and EXISTS Subqueries

DISTINCT Elimination in IN, ANY, and EXISTS Subqueries

An IN, ANY, or EXISTS subquery evaluates to true if there is at least one row that causes the subquery to evaluate to true. These semantics make a DISTINCT within an IN, ANY, or EXISTS subquery unnecessary. The following two queries are equivalent and the first is transformed into the second:

SELECT * FROM t1 WHERE c1 IN
    (SELECT DISTINCT c2 FROM t2 WHERE t1.c3 = t2.c4)
 
SELECT * FROM t1 WHERE c1 IN
    (SELECT c2 FROM t2 WHERE t1.c3 = t2.c4)


Previous Page
Next Page
Table of Contents
Index