Which statement contrasts UNION and UNION ALL correctly?
Correct answer
A. UNION removes duplicate rows and therefore usually needs a sort or hash, while UNION ALL concatenates and keeps duplicates
15 views
A. UNION removes duplicate rows and therefore usually needs a sort or hash, while UNION ALL concatenates and keeps duplicates
15 views
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.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is A? Ask here and get an explanation.