What is the difference between UNION and UNION ALL?

Forums SQLWhat is the difference between UNION and UNION ALL?
Staff asked 2 years ago

Answers (2)

Add Answer
monika gabani Marked As Accepted
Staff answered 2 years ago

Union :

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.

 

 

Staff answered 2 years ago

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.

Subscribe

Select Categories