1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. Which statement contrasts UNION and UNION ALL correctly?

Added 30 Nov -0001

Which statement contrasts UNION and UNION ALL correctly?

  1. UNION removes duplicate rows and therefore usually needs a sort or hash, while UNION ALL concatenates and keeps duplicates Correct answer
  2. Both remove duplicate rows, differing only in the column ordering they produce, so the choice between them is purely cosmetic
  3. UNION requires matching column names, while UNION ALL does not, which is why UNION ALL is faster to write
  4. UNION ALL removes duplicate rows, while UNION keeps them, so the two operators are exact opposites in effect

Correct answer

A. UNION removes duplicate rows and therefore usually needs a sort or hash, while UNION ALL concatenates and keeps duplicates

15 views

MCQSEXAM

Explanation

Set operators: UNION performs an implicit DISTINCT over the combined result, which needs memory or a sort and can be far more expensive than UNION ALL. UNION ALL simply appends the second result and preserves duplicates, so use it whenever duplicates are impossible or harmless. Both require the same number of columns with compatible types, and output names come from the first query.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

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