98. IS NULL, IS NOT NULL, and Three-Valued Logic
MediumNULL HandlingIS NULLIS NOT NULLthree-valued logic
In SQL, col = NULL is never TRUE — comparisons with NULL produce UNKNOWN, which the WHERE clause treats as not-true and filters out. To test for missing values you must use IS NULL / IS NOT NULL. This is the heart of three-valued logic (TRUE / FALSE / UNKNOWN).
Task: the tasks table has an assignee that may be NULL. Return id, title, and status where status is 'unassigned' when assignee IS NULL and 'assigned' otherwise. Then keep only rows that are actually assigned (assignee IS NOT NULL). Order by id.
Output columns, in order: id, title, status.
Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…
This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases — 5test cases in all. A sloppy query that only fits the example won't pass.
SQL· SQLite · runs in your browser
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.