July 2010
Intermediate to advanced
840 pages
16h 33m
English
The [NOT] EXISTS predicate is almost always used with a correlated subquery. Very often the subquery can be “flattened” into a JOIN, which will frequently run faster than the original query. Our sample query can be converted into:
SELECT P1.emp_name, ' has the same birthday as a famous person!' FROM Personnel AS P1, Celebrities AS C1 WHERE P1.birthday = C1.birthday;
The advantage of the JOIN version is that it allows us to show columns from both tables. We should make the query more informative by rewriting it:
SELECT P1.emp_name, ' has the same birthday as ', C1.emp_name FROM Personnel AS P1, Celebrities AS C1 WHERE P1.birthday = C1.birthday;
This new query could be written with an EXISTS() predicate, but that is ...
Read now
Unlock full access