I. MySQL
Only the Union set does not have the keyword of the intersection difference set
Two-Table Structure
A B
Three-Union
3.1 union does not contain duplicate data
SelectNameFromAUnionSelectNameFromB;
3.2 Union all contains duplicate data
Four difference set
Find the ID that exists in Table A but does not exist in Table B
4.1: use Union
Select ID From ( -- Union Select Distinct A. ID As ID From A Union All Select Distinct B. ID As ID From B) Temp Group By ID Having Count (ID) = 1 ;
4.2:Subquery not in
SelectIDFromAWhereIDNot In(SelectIDFromB );
4.3:Subquery not exists
SelectIDFromAWhereNot Exists(SelectIDFromBWhereA. ID=B. ID );
4.4: left join determines that the right table is null
SelectA. IDFromALeft JoinBOnA. ID=B. IDWhereB. IDIs Null Order ByA. ID
Five intersection intersect:
Select ID From ( -- Union Select Distinct A. ID As ID From A Union All Select Distinct B. ID As IDFrom B) Temp Group By ID Having Count (ID) ! = 1 ;