Databases Reference
In-Depth Information
In our query, we select all records in
SALES
(A) minus (
NOT
EXISTS
) records in
CUSTOMERS
(B). So we can use the equivalent A - (A ∩ B) form, using a
LEFT
OUTER
JOIN
:
SELECT AMOUNT_SOLD FROM sh.SALES S
LEFT OUTER JOIN sh.CUSTOMERS C
ON S.CUST_ID = C.CUST_ID
AND C.CUST_CREDIT_LIMIT IN (10000, 11000, 15000)
WHERE C.CUST_ID IS NULL;
The result of the execution of this query is in the next screenshot:
Even if we have the same statistics and almost the same execution plan, the meaning of
the last query isn't as intuitive as in the previous case. So, it's better to avoid using such
transformation in our code, and we have seen that there is no performance improvement
(or detriment) in doing so.