What is the Difference Between UNION and UNION ALL in SQL Server ?

The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected.

UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.

The difference between UNION and UNION ALL is that UNION ALL will not eliminate duplicate rows, instead, it just pulls all rows from all the tables fitting your query specifics and combines them into a table.



You May Interest

Disadvantages of Using Stored Procedures in MS SQL

MS SQL Get Current Time GETDATE()

What is an OUTPUT Clause Inside SQL Server ?

Adding Columns to a Table with a Query in MS SQL

List of Table Columns Used in Any View in MS SQL