【问题标题】:Missing records between INNER and LEFT JOININNER 和 LEFT JOIN 之间缺少记录
【发布时间】:2011-04-13 10:55:58
【问题描述】:

select id from table = 260 595 条记录

select id from table left join table2 on table2.id = table.parent = 260 595 条记录

select id from table inner join table2 on table2.id = table.parent = 260 192 条记录

找出table 中的哪些记录有错误(不存在)连接以便我更正它们的最简单方法是什么?

谢谢。

【问题讨论】:

    标签: select left-join inner-join


    【解决方案1】:
    select id from table left join table2 on table2.id = table.parent
    EXCEPT
    select id from table inner join table2 on table2.id = table.parent
    

    【讨论】:

      【解决方案2】:

      使用这个(它会给你在table2中没有对应记录的表中的id):

      select id 
        from table left join table2 
          on table2.id = table.parent
       where table.parent is null
      

      【讨论】:

        【解决方案3】:
        select id from table inner join table2 on table2.id <> table.parent
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-09-10
          • 2019-09-03
          • 1970-01-01
          • 1970-01-01
          • 2012-08-17
          • 2014-03-11
          • 1970-01-01
          • 2016-12-14
          相关资源
          最近更新 更多