DDR Data Science Interview Practice Test

Access More Questions
Which statement best describes the difference between UNION and UNION ALL?
Correct Answer:
UNION removes duplicates and UNION ALL keeps duplicates, which is faster.
Explanation:
When combining results from multiple queries, the key idea is how duplicates are treated. UNION returns only distinct rows, removing any duplicates that appear across the combined results. UNION ALL keeps every row from both sides, including duplicates, so the same row can appear more than once if it comes from both queries. This difference in handling duplicates is what drives the typical performance gap: removing duplicates requires extra work to identify and drop duplicates, so UNION usually has more overhead and can be slower than UNION ALL. Use UNION when you need a unique set of rows; use UNION ALL when you want to preserve duplicates or when you want the faster, simpler operation and duplicates don’t matter for your result. For example, if one query returns (1, 'x') and the other also returns (1, 'x'), UNION would yield a single (1, 'x'), while UNION ALL would yield two copies of (1, 'x').

Access more questions from this quiz

Continue to DDR Data Science Interview Practice Test for more practice questions and the full quiz experience.

Access More Questions