急!这样的SQL语句能查询出结果吗?
我准备找出两个表中不同的数据,这两个表的结构完全相同,如:
表1:Table1
id a b c
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
表2:Table2
id a b c
1 1 1 2
2 2 2 1
3 3 3 3
4 4 4 4
6 6 6 6
我要得到两个表互不相同的记录的id值,如上面的结果为:
id a b c
1 1 1 1
2 2 2 2
5 5 5 5
6 6 6 6
只需要得到id的值为:1,2,5,6即可!
select id,a,b,c into ##1 from Table1 where id
not in(select id from Table2)
and a not in(select a from Table2)
and b not in(select b from Table2)
and c not in(select c from Table2)
select id,a,b,c into ##2 from Table2 where id
not in(select id from Table1)
and a not in(select a from Table1)
and b not in(select b from Table1)
and c not in(select c from Table1)
select * into ##3 from ##1 union (select * from ##2)
select distinct(id) from ##3
这样怎么不行呀!