1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. SELECT city FROM a EXCEPT SELECT city FROM b; is run where…

Added 30 Nov -0001

SELECT city FROM a EXCEPT SELECT city FROM b; is run where both sides contain a NULL city. How are those NULLs treated?

  1. They are treated as unknown, so every NULL row survives in the resulting output
  2. They abort the query, because set operators reject NULL values in any column
  3. They are duplicated, since set operators never collapse duplicate NULLs
  4. They are treated as equal, so the NULL row is removed from the difference Correct answer

Correct answer

D. They are treated as equal, so the NULL row is removed from the difference

16 views

MCQSEXAM

Explanation

Set operators use two-valued logic: unlike a comparison, EXCEPT and INTERSECT treat NULLs as equal to each other, so a NULL on the left that also appears on the right is removed. UNION likewise collapses duplicate NULL rows that a join would keep apart. This is exactly where EXCEPT behaves differently from NOT IN, which returns nothing when a NULL is present.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? 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