A表里有个Bid字段,B表中也有Bid字段,而且Bid字段会有重复记录
怎么样查询到A表中Bid不在B表中Bid字段不重复记录中的记录

解决方案 »

  1.   

    select
    *
    from a
    where bid
    in (select bid from b group by bid having count(bid)<2)
      

  2.   

    select * from a where bid not in(select bid from b group by bid having count(1)=1)
      

  3.   

    select * from t_BiddingInfo where BiddingId not in (select max(BiddingId) from t_TenderInfo group by BiddingId)
    这样查询可以查出来不在另外一张表的的记录了,现在我还想查出来上面这句话得到的结果中在2个日期之间的
    BiddingId的记录
      

  4.   

    select a.* from a where bid not in (select distinct bid from b)
      

  5.   


    select * from t_BiddingInfo where getDate() between BiddingBeginDate and BiddingEndDate order by BiddingId desc not in (select max(BiddingId) from t_TenderInfo group by BiddingId)这样写提示
    消息 156,级别 15,状态 1,第 1 行
    关键字 'not' 附近有语法错误。
      

  6.   

    select a.* from a where bid not in (select distinct bid from b)select a.* from a where bid not in (select bid from b group by bid having count(1) = 1)
      

  7.   


    select * from t_BiddingInfo where 
    getDate() between BiddingBeginDate and BiddingEndDate order by BiddingId desc 
    not in (select max(BiddingId) from t_TenderInfo group by BiddingId)
      

  8.   

    SELECT * 
    FROM A 
    WHERE NOT EXISTS(
    SELECT 1 
    FROM B
    WHERE A.BID=BID
    GROUP BY BID
    HAVING COUNT(1)<2)
      

  9.   

    语法上应该是这样写的:
    select * from t_BiddingInfo where 
    getDate() between BiddingBeginDate and BiddingEndDate and
    BiddingId not in (select max(BiddingId) from t_TenderInfo group by BiddingId)
    order by BiddingId desc