Union all and Union all

Source: Internet
Author: User

In some cases, it is easy to determine whether a table contains records that meet the conditions. The return value of select count (1) is not 0.

For two structurally similar tables, I initially considered using exist or in, and later found that exist or in is used to filter data. it is equivalent to doing and operations, while union or union all is used for doing or operations and performing addition. so select Union all to judge. select Union all instead of Union because union all does not perform the distinct operation, while Union does distinct and distinct merges duplicate records based on the index. because I only need to determine whether there is a value and do not need to operate on the returned data, we only need to use Union all + count (*) for simple judgment.

Select count (*)
From (select keyid, ideaid
From cpcpartneraudit
Where keyid = 4001 and ideaid = 3001
Union all
Select keyid, ideaid
From cpcpartner
Where keyid = 4001 and ideaid = 3001)

Note that the premise of union or union all is that the record format is the same, for example, both keyid and ideaid.

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.