Reputation: 2161
The following expression
SELECT * FROM t
WHERE a = (SELECT MAX(a) FROM s)
returns nothing when the subquery returns NULL - even if there are NULLs in t.a
.
I would like to return NULL values from t when the subquery returns NULL and non-NULL values from t if there are any matching the subquery.
Is there a clean way to do it?
Upvotes: 3
Views: 82
Reputation: 21376
The expression x IS NOT DISTINCT FROM y
is equivalent to (x = y) OR (x IS NULL AND y IS NULL)
. So:
SELECT * FROM t
WHERE a IS NOT DISTINCT FROM (SELECT MAX(a) FROM s)
Upvotes: 4