3 ms·
SELECT 'foo' WHERE bar = baz FROM quux UNION ALL SELECT 'bar' WHERE bar <> baz FROM quux I would understand returning an error in that case if bar or baz w
by Pxtl 7y ago
SELECT 'foo' WHERE bar = baz FROM quux
UNION ALL
SELECT 'bar' WHERE bar <> baz FROM quux
I would understand returning an error in that case if bar or baz were unknown. The truthiness of bar = baz is unknown, so that's an error.
But that's not what SQL Servers do. They're all pedantic about how NULL means unknown right up until the rubber hits the road of the WHERE clause, when suddenly NULL means false.
Which means that they're not saying that foo = bar is unknown, they're instead making a definitive assertion that both foo = bar is false and foo <> bar is false. And that's disastrously wrong.
- sjwright 7y agoHard disagree. It should be impossible to make any truthful claim about a NULL with respect to any other value including NULL. Thus it is correct that both foo = bar is false and foo <> bar is false. Were it any other way, joins wouldn’t work properly.