1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. What does WHERE col <> 'x' do with rows where col IS NULL?

Added 30 Nov -0001

What does WHERE col &lt;&gt; 'x' do with rows where col IS NULL?

  1. It includes them only if the column is indexed, since the index stores a default value
  2. It includes them, because NULL differs from every value including the string x
  3. It excludes them, because NULL &lt;&gt; 'x' evaluates to UNKNOWN rather than TRUE Correct answer
  4. It raises an error unless col is declared NOT NULL, because the comparison is invalid

Correct answer

C. It excludes them, because NULL &lt;&gt; 'x' evaluates to UNKNOWN rather than TRUE

15 views

MCQSEXAM

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

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs