Show that, in SQL, ALL is identical to NOT IN.


Let r1 and r2 be two relations having only one attribute say k.

Let the following be called “query 1”.

SELECT k
FROM r1
WHERE k <> ALL (
    SELECT k
    FROM r2
)

Let the following be called “query 2”.

SELECT k
FROM r1
WHERE k NOT IN (
    SELECT k
    FROM r2
)

As you can see query 1 and query 2 are almost the same, except we replaced ”<> ALL” in query 1 by “NOT IN” in query 2. If we can show that the two queries give the same result i.e. the same set of tuples, we have shown that ALL is identical to NOT IN.


Take any tuple from the result of query 1, say . Since is in relation and not equal to any tuple of relation , it is not in relation . Therefore is in the result of query 2.


Take any tuple from the result of query 2, say . Since is in relation and not in relation , it is not equal to any tuple of relation . Therefore is in the result of query 1.


Thus the result of the two queries is identical.


Which proves in general case that ALL is identical to NOT IN.