不要用not in用not exist或者做left join where xxxx is null

解决方案 »

  1.   

    select * 
    from tblThread
    where topic_ID not in
    (
    select topic_ID
    from tblTopic
     )
      

  2.   

    SELECT tblThread.*, bltopic.*
    FROM tblThread CROSS JOIN
          bltopic
    WHERE (tblThread.topic_id NOT IN
              (SELECT tblThread.topic_id AS Expr1
             FROM tblThread INNER JOIN
                   bltopic ON tblThread.topic_id = bltopic.topic_id))这样只能将tblThread中的列出,bltopic中存在,但tblthread中不存在的没有列出.
    当然用这咱笨办法,再加上几行是就以解决的.
      

  3.   

    left/ right/ full/ cross jion 
    如果a中有的,B中没有.B中有的,A中没有,列去这个集合.有没有好的方法呢.
      

  4.   

    如果只是查Topic_ID
    select case when Col1 is null then Col2 else Col1 end from
    (select tblThread.Topic_ID as Col1,tblTopic.Topic_ID as Col2 from tblThread
    full join tblTopic on tblTopic.Topic_ID = tblThread.Topic_ID)A
    查出整条纪录
    select * from tblThread
    where not exists(select Topic_ID from tblTopic where tblThread.Topic_ID = Topic_ID.Topic_ID)
    union all
    select * from tblTopic
    where not exists(select Topic_ID from tblThread where tblThread.Topic_ID = Topic_ID.Topic_ID)