What is the difference between UNION and UNION ALL?
Answers (2)
Add AnswerUnion :
Union extracts the rows that are being specified in the query.
Union is used to combine two queries into a single result set using the select statements. Union extracts all the rows that are described in the query.
Union All :
Union All extracts all the rows including the duplicates (repeated values) from both the queries.
Union All is used for extracting all the rows from a set of two tables.
Union is eliminates the duplicate values/data while Union All will return all data no matter how many rows/data are identical or say repeating.
Select ‘Mihir’ As FirstName
Union
Select ‘Mihir’ As FirstName
Above code will return only 1 row, while if you apply Union All in above code it will return same data 2 times.