Warm tip: This article is reproduced from stackoverflow.com, please click
mysql sql teradata

SQL ALL COMMAND, SUBQUERY RETURNS NULL BUT OUTPUT GIVES ALL RECORDS

发布于 2020-03-27 10:21:09

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?

Questioner
Vamsi Chand Emani
Viewed
118
dnoeth 2019-07-03 22:07

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?