MySQL多表查询

575 查看

1. 两张表都有的记录

select * from Table_1 where exists (select Column_2 from Table_2 where Colomn_2=Table_1.Column)

2. 表一有表二没有的记录

select * from Table_1 where not exists (select Column_2 from Table_2 where Colomn_2=Table_1.Column)

3. 表二有表一没有的记录

select * from Table_2 where not exists (select Column_1 from Table_1 where Colomn_1=Table_2.Column)