1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. SELECT DISTINCT city, country FROM customers; is executed…

Added 30 Nov -0001

SELECT DISTINCT city, country FROM customers; is executed. What exactly is deduplicated?

  1. Only the city column, because DISTINCT applies to the first selected expression only
  2. Only the country column, since the last expression in the list takes precedence
  3. Both columns independently, producing the cross product of unique values
  4. Whole (city, country) pairs, so a city may still appear once per distinct country Correct answer

Correct answer

D. Whole (city, country) pairs, so a city may still appear once per distinct country

15 views

MCQSEXAM

Explanation

DISTINCT removes duplicate rows from the whole select list, so the (city, country) pair is the unit of comparison, not the first column alone. To deduplicate one column while keeping the others you need DISTINCT ON in PostgreSQL or a window function such as ROW_NUMBER. COUNT(DISTINCT city) counts unique cities without changing the row shape.

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