Why does a WHERE clause such as WHERE bonus = NULL never return rows?
Correct answer
C. A comparison with NULL is unknown, never true
15 views
C. A comparison with NULL is unknown, never true
15 views
SQL uses three-valued logic, and any comparison with NULL yields UNKNOWN, which WHERE treats as false, so = NULL filters out every row. The correct predicate is IS NULL or IS NOT NULL, and ifnull-style functions handle replacement values. The same rule explains why NOT IN (subquery containing a NULL) returns no rows: the comparison becomes UNKNOWN for every candidate.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is C? Ask here and get an explanation.