For example
First, create a, b two tables, in order to facilitate understanding, both tables create only one field column, respectively, A_col and B_col, add a table
Data 1, 4, 5, 9, add B table Data 2, 3, 4, 5.
Second, enter the following statement: SELECT * FROM A Union SELECT * FROM B;
Results: 1, 4, 5, 9, 2, 3. (Remove duplicate rows)
Enter the following statement: SELECT * FROM A UNION ALL SELECT * from B;
Results: 1, 4, 5, 9, 2, 3, 4, 5. (duplicate rows not removed)
Conclusion
Union: Set operation on two result sets, excluding duplicate rows, and sorting the default rules;
Union All: Set operation on two result sets, including repeating rows, without sorting;
"Precautions"
Using union and UNION all must ensure that the results of each select collection have the same number of columns, and that the type of each column is
Same, but column names do not necessarily need to be the same.
This article is from the "Wooden Monkey" blog, please be sure to keep this source http://694746637.blog.51cto.com/9310943/1690367
Differences in the Union and union ALL in Oracle