缺少INNER和LEFT JOIN之间的记录

时间:2011-04-13 10:55:58

标签: select left-join inner-join

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中哪些记录有错误(不存在)的最简单方法是什么,以便我可以纠正它们?

感谢。

3 个答案:

答案 0 :(得分:2)

使用它(它会在表格中给出你在table2中没有相应记录的id):

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

答案 1 :(得分:2)

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 :(得分:0)

select id from table inner join table2 on table2.id <> table.parent