日期:2014-05-16  浏览次数:20510 次

急用!!!如何提取出与表B不同的表A的记录
现有表tbA和tbB,字段一样,记录数不一样,比较字段notext的记录,提取出与表B不同的表A的notext记录

举例,表tbA
notext	blu
01 04 19 22 24 25 01
15 18 23 27 32 33 15
03 04 07 17 21 27 03
08 10 12 14 18 28 08
05 14 16 21 29 30 05
08 09 19 20 25 32 08
05 07 08 20 31 33 05
09 10 13 14 21 32 09
01 08 11 19 21 24 01
05 09 13 15 17 21 05
04 09 19 22 25 29 04
02 11 19 30 32 33 02
02 03 07 13 21 24 02
04 06 07 14 25 26 04
13 17 18 21 30 33 13
02 10 15 19 20 21 02
09 14 17 23 24 25 09
08 10 15 17 22 29 08
04 06 07 10 21 26 04


表tbB
notext	blu
08 10 12 14 18 28 08
05 14 16 21 29 30 05
08 09 19 20 25 32 08
05 07 08 20 31 33 05
09 10 13 14 21 32 09
01 08 11 19 21 24 01
05 09 13 15 17 21 05
04 09 19 22 25 29 04
02 11 19 30 32 33 02
02 03 07 13 21 24 02
04 06 07 14 25 26 04
13 17 18 21 30 33 13
02 10 15 19 20 21 02
09 14 17 23 24 25 09
08 10 15 17 22 29 08
04 06 07 10 21 26 04
07 09 13 17 21 22 07
08 10 16 20 23 30 08
01 05 10 14 16 30 01


提取出与表B不同的表A的记录,执行了一下语句
 select * from tbB union select * from tbA limit cnt

错误
引用
消息 102,级别 15,状态 1,第 1 行
'cnt' 附近有语法错误。


请教大神帮助纠正及指教,谢谢。

我要的结果应该是
notext
01 04 19 22 24 25
15 18 23 27 32 33
03 04 07 17 21 27

------解决方案--------------------
select * from tbA
except
select * from tbB


------解决方案--------------------
select * from tba as a where not exists(select 1 from tb b where notext=a.notext)

------解决方案--------------------
或者:
select * from tbA  where   notext not in (select notext from tbB)