或者: select id from ( select distinct id from tableA union all select distinct id from tabelB ) a group by id having count(*)=1
select a.id from 表1 a full join 表2 b on a.id=b.id where a.id is null or b.id is null --或 select id from 表2 a where not exists(select 1 from from 表1 where a.id = id)
select * from 2 where id not (select id from 1 )
select a.id from 表1 a full join 表2 b on a.id=b.id where a.id is null or b.id is null
create table a1(a int)create table a2(a int)insert a1 select 1 union select 2 union select 3 union select 5 union select 6insert a2 select 1 union select 2 union select 3 union select 4 union select 6 union select 7 select * from a1 where a not in (select * from a2) union select * from a2 where a not in (select * from a1)
select id
from
( select distinct id from tableA
union all
select distinct id from tabelB
) a
group by id
having count(*)=1
from 表1 a full join 表2 b on a.id=b.id
where a.id is null or b.id is null
--或
select id from 表2 a where not exists(select 1 from from 表1 where a.id = id)
from 表1 a full join 表2 b on a.id=b.id
where a.id is null or b.id is null
select 1
union select 2
union select 3
union select 5
union select 6insert a2
select 1
union select 2
union select 3
union select 4
union select 6
union select 7
select * from a1 where a not in (select * from a2)
union select * from a2 where a not in (select * from a1)