MySQL Note-union

Source: Internet
Author: User

Union syntax

Select ...

Union [all | distinct]

Selct ...

    1. The union is used to combine results from multiple SELECT statements in a single result set.
    2. the list of two queries must be the same , otherwise the "The used SELECT statements has a different number of columns"
    3. Multiple SELECT statements can be removed with different field names, without error, but when the final result set is displayed, the field name of the first SELECT statement will prevail.
    4. When you remove the same data from multiple SELECT statements, union merges the same columns, and it must be explained that the so-called same means that all the fields are identical in content
    5. If you do not want to remove the duplicate rows, use the UNION ALL
    6. If there is an order by,limit in the clause, enclose it in parentheses (). After all clauses are recommended, the result set of the final merge is sorted or filtered.
    7. In clauses, the order by needs to be used with limit to make sense. If not used with limit, it will be removed by the parser optimization analysis.

MySQL Note-union

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.