UNION vs UNION ALL
Learn the different between union and union all SQL statement and their performance.
UNION
The UNION command is used to select related information from two tables, which is like a JOIN command. However, when using UNION command, all the selected columns need to be of the same data type. With UNION, only distinct values are selected.
UNION ALL
UNION ALL command is equal to UNION command, except that UNION ALL selects all the values.
The difference between Union and Union all is that Union all will not eliminate duplicate rows, instead it just pulls all the rows from all the tables fitting your query specifics and combines them into a table.
A UNION statement effectively does a SELECT DISTINCT on the results set. If you know that all the records returned are unique from your union, use UNION ALL instead, it gives faster results.
Example
Table 1 : First,Second,Third,Fourth,Fifth
Table 2 : First,Second,Fifth,Sixth
Result Set
UNION: First,Second,Third,Fourth,Fifth,Sixth (This will remove duplicate values)
UNION ALL: First,First,Second,Second,Third,Fourth,Fifth,Fifth,Sixth,Sixth (This will repeat values)

Sai YangPosted Dec 6, 2021, 5:38 AM
Hi sir, I am new coming here. Could you explain the query sorted for Union/Union all? Ex: I have two queries, first one is either has row and second one has some rows.
Peter Schmitz .·.Posted Jul 22, 2020, 6:45 AM
Your result set for UNION ALL is wrong. There's only one "sixth" result (from Table 2. Table 1 does not contain a value called 'Sixth')
David WelsonPosted Jun 2, 2020, 9:46 AM
Good to see that you are making good use of your talent. Conveying your knowledge to other people is definitely a remarkable deed. Keep it going. Loved your work. https://techleem.com/taylor-alesia/
kevin bearPosted Jun 1, 2020, 1:12 AM
Thanks for providing this amazing stuff your article is very used full for me such a nice content provide i love it dear https://www.usajacket.com/product/captain-marvel-carol-danvers-leather-jacket/
R JPosted Nov 29, 2019, 3:55 PM
Anu, I am looking for a good asp.net skills. Write me if interested. RJ
SaraMcintoshPosted Apr 26, 2019, 7:58 AM
STOP PLAGIARIZING OR ATLEAST ADD REFERENCES. SIMPLY COPYING OTHER PEOPLE WORK WORD TO WORD IS BADD.
Muhammad Ashikuzzaman AshikPosted Mar 1, 2019, 11:04 PM
Thanks for nice info.
Thennarasu NPosted Apr 6, 2017, 8:53 AM
Thank you for Sharing