Form A
id | name | age | city |
1 | a | 18 | beijing |
2 | b | 20 | beijing |
id | school | city |
1 | m | beijing |
3 | n | beijing |
5 | p | sichuan |
Assuming that the partition of the two tables is city, the current requirement is to find the information that exists in table A but does not exist in table B (AB). The filter condition is "id" and city='beijing':
select A.id from( (select * from A where A.city = 'beijing') T1 left outer join (select * from B where B.city = 'beijing') T2 on A.id = B.id and B.id is NULL )
The final result of the above statement is: "1" . That is, it realizes the difference set of two tables based on id.