SQL UNION ALL Syntax. UNION first performs a sorting operation and eliminates of the records that are duplicated across all columns before finally returning the combined data set. The results from a UNION ALL are unsorted. To combine rows from two or more queries into a single result set, we use UNION operator. The difference between Union and Union all is that UNION ALL will not eliminate duplicate rows, instead it just pulls all rows from all tables fitting your query specifics and combines them into a table.. A UNION statement effectively does a SELECT DISTINCT on the results set.. The UNION operator removes eliminate duplicate rows, whereas the UNION ALL operator does not.. Because the UNION ALL operator does not remove duplicate rows, it runs faster than the UNION operator.. But UNION ALL won’t filter any records. However, Union all works fairly faster than the Union command. If the option is to keep the duplicate values, then the UNION ALL keyword should be used. The UNION ALL operator performs -in a similar way to the UNION operator, in the sense that it too combines the result sets of two or more SELECT statements. The difference lies within the results; UNION ALL allows duplicate records in the results as UNION does not. This is because there is no onus on the Union all command to eliminate duplication and present distinct values. The final result set contains all the rows returned by all the queries in the UNION ALL, but it also contains duplicate records. In the execution plan of both SQL Union vs Union All, we can see the following difference. When DB2 encounters the UNION keyword, it processes each select / subselect to form an interim result table, then it combines the interim result table and deletes duplicate rows to form a combined result table working similar as a JOIN. The following image illustrates the UNION ALL. The differences between these two is pretty simple, when using just the UNION keyword, duplicates records will be eliminated while the UNION ALL will include any duplicates. Syntax Example If you execute this statement against the AdventureWorks2014 database you will see that it will return 20,077 rows and will include duplicates. A ORDER BY should be inserted with the last SELECT statement. The following are rules to union data: The number of columns in all queries must be the same. Similar to UNION, it combines results generated by multiple SQL queries or tables and returns a single result set. SQL Union contains a Sort operator having cost 53.7% in overall batch operators Sort operator could be more expensive if we work with large data sets Order By clause in SQL Union vs Union All clause UNION All is also the SET operators. UNION and UNION ALL are used to combine two Query results vertically into one Query, therefore both Queries require to have the same number of fields and same data types. Union all, as its name suggests, returns all the values specific to the query, inclusive of the values that have been duplicated as well. The difference between Union and Union all is that Union all will not eliminate duplicate rows, instead it just pulls all rows from all tables fitting your query specifics and combines them into a table. UNION ALL is also a ‘set operator’ in SQL Server. Both UNION and UNION ALL operators combine rows from result sets into a single result set. UNION ALL keeps all of the records from each of the original data sets, UNION removes any duplicate records. What is UNION ALL. UNION vs UNION ALL. UNION ALL. It is like applying DISTINCT on the final result rest. UNION ALL The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values. In short, the difference between UNION operator and UNION ALL (UNION vs UNION ALL) operator is UNION gives unique results set in the output even though the combined result set has some duplicate records. SELECT column_name(s) FROM table1. UNION ALL Difference. If you select Distinct from Union All result set, Then the output will be equal to the Union result set. When two Queries are combined, there could be rows of record that are exactly the same (duplicates). … UNION ALL. Union vs. Union All Query Syntax for SQL Server and Microsoft Access Union Query Overview The purpose of the SQL UNION and UNION ALL commands are to combine the results of two or more queries into a single result set consisting of all the rows belonging to all the queries in the union. So after getting the results, you can sort them by using the ORDER BY clause.