+ -
当前位置:首页 → 问答吧 → 比对两张表

比对两张表

时间:2011-12-07

来源:互联网

表1表2字段完全相同,行数也完全相同。如:
b1
 w ww www
 1 2 3
 2 3 4
 3 4 5
b2
 w ww www
 1 2 3
 2 3 4
 3 4 6

现在要判断两张表,哪些行字段值不同要怎么写。我自己写的感觉都不对。

作者: xasql   发布时间: 2011-12-07

SQL code
select * from b1 t where not exists(select 1 from b2 where w=t.w and ww=t.ww and www=t.www)

作者: fredrickhu   发布时间: 2011-12-07

SQL code
select w+ww+www from b1 where not exsits (select w+ww+www from b2)

作者: xuam   发布时间: 2011-12-07

SQL code
select * from b1 t 
where not exists(select 1 from b2 where w=t.w and ww=t.ww and www=t.www)

作者: lzd_83   发布时间: 2011-12-07

SQL code
SELECT * FROM b1
EXCEPT
SELECT * FROM b2


/*
w    ww    www
3    4    5
*/


SELECT * FROM b2
EXCEPT
SELECT * FROM b1

/*
w    ww    www
3    4    6*/



作者: OrchidCat   发布时间: 2011-12-07