【问题标题】:fastest way to find non-matching ids from two tables从两个表中查找不匹配 id 的最快方法
【发布时间】:2011-09-25 14:26:18
【问题描述】:

我有 1000 个值的基表。第二个临时表有 100 个值。我需要通过 guid 比较它们并只返回第二个表中不存在于第一个表中的那些行。为此,我需要最快的性能解决方案。谢谢!

【问题讨论】:

    标签: sql sql-server-2008-r2


    【解决方案1】:

    经典的左连接/isnull 测试

    select A.*
    from secondTbl A
    left join firstTbl B on A.guid = B.guid
    WHERE B.guid is null
    

    【讨论】:

      【解决方案2】:
      SELECT * FROM Table2 WHERE 
          NOT EXISTS (SELECT 'x' FROM table1 where 
              table1.field= table2.field)
      

      http://weblogs.sqlteam.com/mladenp/archive/2007/05/18/60210.aspx

      【讨论】:

        猜你喜欢
        • 2015-09-06
        • 1970-01-01
        • 2017-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-26
        • 2014-02-24
        • 1970-01-01
        相关资源
        最近更新 更多