The usage of Union and Union All in SQL statements. The SQL statement unionall

Source: Internet
Author: User

The usage of Union and Union All in SQL statements. The SQL statement unionall

In SQL, Union and Join statements are very similar, but Union has a condition that the columns produced by two SQL statements must be of the same data type, different data values are displayed in the final result.

Format:

[SQL statement 1]
UNION
[SQL statement 2]

For example:

Table store_info

And table internet_sales

Use the Union statement:

Copy codeThe Code is as follows: SELECT Date FROM Store_Info
UNION
SELECT Date FROM Internet_Sales

Result:

Or:

Copy codeThe Code is as follows: SELECT Date, Sales FROM Store_Info
UNION
SELECT Date, Sales FROM Internet_Sales

Result:

Finally, Union All and Union are basically the same. The difference is that their results contain duplicate data.

For example:

Copy codeThe Code is as follows: SELECT Date FROM Store_Info
UNION ALL
SELECT Date FROM Internet_Sales

Result:

The above is All about the usage of the Union and Union All statements in SQL statements. I hope you can give us a reference, and I hope you can provide more support to the customer center.

Related Article

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.