In the SQL statement: The difference between the Union and UNION all

Source: Internet
Author: User
The more union all is a direct connection, takes all values, records may have duplicate   Union is a unique value, record is not duplicated   
1. The syntax of UNION is as follows:
[SQL Statement 1]
UNION
[SQL Statement 2]

2. The syntax of UNION all is as follows:
[SQL Statement 1]
UNION All
[SQL Statement 2]

Efficiency:
The Union and UNION ALL keywords combine two result sets into one, but they differ in both usage and efficiency.

1. Processing of duplicate results: Union will filter out duplicate records after the link is made, and union all will not remove duplicate records.

2, the processing of sorting: the Union will be sorted in the order of the fields; UNION all simply merges two results and returns.

In terms of efficiency, union All is much faster than union, so if you can confirm that the combined two result sets do not contain duplicate data and do not require sorting, then use UNION ALL.

In the SQL statement: The difference between the Union and UNION all

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.