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.