有两个表,分别是:A和B,A和B的结构都一样,
A:HUOPINCODE    HUOPINNAME
000001        螺丝丁
000002        螺丝帽
000003        螺旋丁
B:HUOPINCODE    HUOPINNAME
000001        螺丝丁2
000003        螺旋丁
我想求出的结果是:HUOPINCODE    HUOPINNAME
000001        螺丝丁2也就是B表中有的记录A表中也有就不显示,如果B表中有,A表中没有就显示出来。谢谢各位!!!!!!!!
马上结帖

解决方案 »

  1.   

    select * from B where checksum(*) not in(select checksum(*) from A)
      

  2.   

    select * from B where not exists(select 1 from A where HUOPINCODE=B.HUOPINCODE and HUOPINNAME=B.HUOPINNAME)
      

  3.   

    declare @t table(HUOPINCODE varchar(10),HUOPINNAME varchar(10))
    declare @a table(HUOPINCODE varchar(10),HUOPINNAME varchar(10))
    insert into @t 
    select '000001','螺丝丁' union all
    select '000002','螺丝帽'union all
    select '000003','螺旋丁'insert into @a 
    select '000001','螺丝丁2' union all
    select '000003','螺旋丁'
    select a.* from @a a,@t b where a.HUOPINCODE=b.HUOPINCODE and a.HUOPINNAME<>b.HUOPINNAME
      

  4.   

    select * from B where checksum(*) not in(select checksum(*) from A)