Interview › NULL three-valued logic
SQL interview: why WHERE col <> 'x' dropped the NULLs
The filter is not false. It is unknown. Unknown rows vanish.
Prompt. All orders that are not Cancelled, including those with a NULL status.
Hint: WHERE status <> 'Cancelled' OR status IS NULL
SELECT * FROM Orders
WHERE status <> 'Cancelled' OR status IS NULL;
-- or
WHERE ISNULL(status, '') <> 'Cancelled';
ISNULL in a WHERE can kill a seek. The OR IS NULL form is the honest one.
Then write it on a ticket
Monday is free. A colleague asks, you type, we mark it.
Clock in free