Using ALL
command in SQL, the subquery returns NULL values but the query is giving all the records in the table.
SELECT * FROM STORES
WHERE STORE_NUMBER = ALL(SELECT STORE_NUMBER FROM STORES WHERE STORE_NUMBER>10000)
The Subquery:
SELECT STORE_NUMBER FROM STORES WHERE STORE_NUMBER>10000
Returns 0 records
But when I run the whole query it gives me all the records in the Stores
table. Isn't it supposed to give NULL values?
Well, this is how = ALL
is supposed to work according to Stnadrad SQL: if the subquery returns no rows (or all returned rows share the same value) the condition is evaluated to TRUE
.
But why do you want to use = ALL
, it's very uncommon?