Differences in the Union and union ALL in Oracle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.