1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. When GROUP BY runs on a column containing NULLs, how are…

Added 30 Nov -0001

When GROUP BY runs on a column containing NULLs, how are those rows treated?

  1. The rows are excluded from the result entirely, because the grouping key is missing
  2. The query fails unless NULLs are filtered out first, since grouping needs a known key
  3. All NULLs form a single group, because GROUP BY treats them as equal to each other Correct answer
  4. Each NULL forms its own separate group, because NULL is never equal to another one

Correct answer

C. All NULLs form a single group, because GROUP BY treats them as equal to each other

14 views

MCQSEXAM

Explanation

Grouping and NULL: GROUP BY uses a grouping notion of equality in which NULLs count as equal, so any number of NULL rows collapse into one group. This deliberately differs from the = operator, where NULL = NULL is UNKNOWN. Placement of NULLs by ORDER BY is a separate, dialect-specific matter, with PostgreSQL sorting them last in ascending order.

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