-
If a query/subquery doesn’t find any matching rows, then it either returns NULL or no value at all, thus not even a NULL value. Based on
what criteria does a query/subquery return a NULL and when doesn’t it return any results, not even a NULL value? -
Will a scalar subquery always return NULL, when no
matching rows are found? I assume most-outer scalar query also returns
NULL if no rows are found? -
SELECT FirstName, LastName, YEAR(BirthDate) FROM Persons WHERE YEAR(BirthDate) IN (SELECT YearReleased FROM Albums);-
If the subquery finds no results, is the WHERE clause of the outer
query translated intoWHERE YEAR(BirthDate) IN (null);? -
If WHERE clause is translated into
WHERE YEAR(BirthDate) IN();instead, shouldn’t that be an error condition, since how canYEAR(BirthDate)value be compared to nothing?
-
If a query/subquery doesn’t find any matching rows, then it either returns NULL or
Share
The subquery would only ever return
NULLwhenYearReleasedwasNULL, otherwise there would be an empty recordset, making it theIN ()case you mentioned.It’s very important to distinguish between the two as they mean entirely different things.
NULLindicates that there was something to beSELECTed, although that value indicates a “lack of value” so to speak. An empty recordset indicates that there was nothing to be selected that matched the criteria specified.EDIT: updated to show example results
First two queries are just to show what’s in the two tables. Third query is your query and the fourth query just shows that it produces an equivalent result (no rows) if you replace the subquery with a
NULL. Last query is just to show that the subquery itself just returns a big list ofNULLs.