34,838
社区成员




select aa.col1,aa.col2,aa.col3, ... ,bb.col1,bb.col2 from table1 aa,table2 bb
where aa.ID = bb.ID
select aa.col1,aa.col2,aa.col3, ... ,bb.col1,bb.col2 from table1 aa,table2 bb
where aa.ID not in (Select ID from table2)
select aa.col1,aa.col2,aa.col3, ... ,bb.col1,bb.col2 from table1 aa left join table2 bb
on aa.id=bb.id
where bb.id is null
union
select aa.col1,aa.col2,aa.col3, ... ,bb.col1,bb.col2 from table1 aa right join table2 bb
on aa.id=bb.id
where aa.id is null
--table1有table2没有的
select * from table1 where ID not in (Select ID from table2)
--table2有table1没有的
select * from table2 where ID not in (Select ID from table1)
--什么,两个都要,对表字段不明,只能取ID
select id,'table2没有' from table1 where ID not in (Select ID from table2)
union
select id,'table1没有' from table2 where ID not in (Select ID from table1)
--try:
select aa.col1,aa.col2,aa.col3, ... ,bb.col1,bb.col2 from table1 aa left join table2 bb
on aa.id=bb.id and bb.id is null