现在有tab1,tab2表,tab1 :
     name   count
     苹果    20
     香蕉    12
     橘子    23
     汽车    10tab2:
     name    count
     苹果    20
     香蕉    12
     橘子    23
我要查询出tab1表中,在tab2表没有的数据"汽车"来,应该怎么写sql语句

解决方案 »

  1.   

    declare @t table(name varchar(10),[count] int)
    insert into @t select '苹果'    ,20
    union all select '香蕉'    ,12
    union all select '橘子'    ,23
    union all select '汽车'    ,10declare @a table(name varchar(10),[count] int)
    insert into @a select '苹果'    ,20
    union all select '香蕉'    ,12
    union all select '橘子'    ,23select * from @t where name not in(select [name] from @a)
      

  2.   

    续楼上测试环境select * from @t a where not exists(select 1 from @a where name=a.name)