"SQL Optimization" union, union all, or use

Source: Internet
Author: User

1. Union: Set operation on two result sets, go to weight, sort by default rule

2. UNION ALL: Set operation on two result sets, do not go heavy, do not sort

3, Intersect: the intersection of two result sets, go to heavy, sorted by default rules

4, minus: For two result sets of the difference operation, go to heavy, according to the default rules sort

5, or: Meet the two conditions of the set, do not go heavy, do not sort

The following conclusion concludes:

1, if the or field is an indexed field, then use union all instead of or operation, you can walk the index

2, if you can use union all, try not to use union, equivalent to want to distinct and executed the order by

3, the default collation described here is sorted by the order of the fields behind the Select, sorted by first field, sorted by the second field if the first field is the same

"SQL Optimization" union, union all, or use

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.