What is the difference between UNION and UNION ALL in SQL?
Correct answer
B. UNION removes duplicate rows; UNION ALL keeps every row
18 views
B. UNION removes duplicate rows; UNION ALL keeps every row
18 views
UNION merges result sets and then eliminates duplicate rows, which requires a sort or hash step and therefore extra cost. UNION ALL simply concatenates the rows and keeps duplicates, making it considerably faster when duplicates are impossible or acceptable. Both require the same number of columns with compatible types, and neither guarantees result order without an explicit ORDER BY.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is B? Ask here and get an explanation.