What does WHERE col <> 'x' do with rows where col IS NULL?
A
It includes them only if the column is indexed, since the index stores a default value
B
It includes them, because NULL differs from every value including the string x
C
It excludes them, because NULL <> 'x' evaluates to UNKNOWN rather than TRUE
Correct answer
D
It raises an error unless col is declared NOT NULL, because the comparison is invalid
Correct answer
C. It excludes them, because NULL <> 'x' evaluates to UNKNOWN rather than TRUE
15 views
⚔️
Challenge a friend on SQL for Data Analysis
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
Explanation
Three-valued logic means comparisons involving NULL yield UNKNOWN, and WHERE keeps only rows whose predicate is TRUE, so NULL rows drop out of both col = 'x' and col <> 'x'. Adding OR col IS NULL restores them. The IS DISTINCT FROM operator performs a null-safe comparison instead.
Reference
Asked in: NTS, PPSC IT, Interviews
Doubts & discussionNot sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ A LEFT JOIN carries the right-table condition b.status = 'active' in the WHERE clause instead of the ON clause. What is the effect? Next MCQ › Counting customers by joining customers to orders and using COUNT(*) inflates the number. Why, and what fixes it?