我这想通过一条sql语句,查询两表中,不同的数据。
select billno from declarebill dl,(select billno from checkcapital)cp where dl.Check_Money=1 and dl.billno<>cp.billno
我的意思是declarebill中凡是符合Check_Money=1,并且是dl.billno<>cp.billno不相等的数据,但好像执行出来的结果不对,应该如何写个sql语句呢?

解决方案 »

  1.   

    == 5min
    == 思想重于技巧 ==
      

  2.   

    select billno 
    from declarebill dl
    where billno not in (select billno from checkcapital)
    and Check_Money=1
    == 思想重于技巧 ==
      

  3.   

    select dl.billno
    from declarebill dl left join checkcapital cp on dl.billno=cp.billno
    where dl.Check_Money=1 and cp.billno is null
    == 思想重于技巧 ==
      

  4.   

    子查询有问题,没有看到记录及正确结果,TRY:
    select dl.billno from declarebill dl left join checkcapital cp on dl.billno=cp.billno
    where dl.Check_Money=1 and cp.billno is null
      

  5.   


    select a.billno from declarebill as a left join checkcapital as b using(billno) where a.Check_Money = 1 and b.billno is null;
      

  6.   

    LEFT JOIN 的这条语句是最优化的。