想让表2的列的值跟表1的列的值对比.列出不一样的数据(表2的数据比较多)
想要知道表2比表1多了那些数据jsptab表1

tmitem表2
列item_subno

解决方案 »

  1.   

    select t2.* from t2 where item_subno not in (select tm from t1)
    select t2.* from t2 where not exists (select 1 from t1 where t1.tm = t2.item_subno)
      

  2.   


    --表2列出表1沒有數據
    select item_subno from jsptab
    except
    select tm from jsptab 
      

  3.   


    服务器: 消息 156,级别 15,状态 1,行 2
    在关键字 'except' 附近有语法错误。
      

  4.   

    谢谢大家.可以了
    select t2.* from t2 where item_subno not in (select tm from t1)
    select t2.* from t2 where not exists (select 1 from t1 where t1.tm = t2.item_subno)
      

  5.   

    select * from t2 where not exists (select 1 from t1 where tm = t2.item_subno)---简化一点点 不要那么多前缀
      

  6.   

    也可以:
    select * from t2 where checksum(*) not in(select checksum(*) from t1)
      

  7.   

    想让表1的列1的值跟表2的列1的值对比.如果值相同.就去对列2的数据.列出不同值(两个表的列2都是价格)想要知道两个表那些价格不一样jsptab表1
    列1    列2
    tm    lsjitem表2  列1 item_subno  列2 sale_price
      

  8.   

    --要指定对比的列
    select * from 表2 a where not exists(select 1 from 表1 where id=a.id)
    --此处用id来对比,也可以用其他列来对比.
      

  9.   

    这是SQL2005的用法,你的环境应该是 SQL2000?
      

  10.   


    这样比较
    select 
    *
    from jsptab as a
    full join 
    item as b on a.tm=b.item_subno and a.sale_price=b.sale_price
    where nullif( a.tm,b.item_subno) is not null
      

  11.   


    都可用 full join+nullif
      

  12.   


    建议使用except,not in 的效率不高。