SQL statement intersetct, minus, Union, Union all summary

Source: Internet
Author: User

The operations of intersect and minus are basically the same as those of Union. Here we will summarize the following:

 

Union: Perform Union operations on two result sets, excluding duplicate rows, and sort the default rules at the same time;

 

Union all: Perform Union operations on the two result sets, including duplicate rows without sorting;

 

Intersect: intersection of two result sets, excluding duplicate rows, and sorting by default rules;

 

Minus performs the Difference Operation on two result sets, excluding duplicate rows and sorting by default rules. (Only the content in the first SQL statement is displayed. If the content in the first SQL statement is in the second SQL statement, it is removed. If it is not in the second SQL statement, it is displayed)

 

You can specify the order by clause in the last result set to change the sorting method.

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.