1

select id from table = 260 595 records

select id from table left join table2 on table2.id = table.parent = 260 595 records

select id from table inner join table2 on table2.id = table.parent = 260 192 records

What is the easiest way to find out what records in table have wrong (nonexistent) join so I can correct them?

Thanks.

animuson
  • 53,861
  • 28
  • 137
  • 147
feronovak
  • 2,687
  • 6
  • 35
  • 54

3 Answers3

2

Use this(it will give you id's in table that doesn't have corresponding records in table2):

select id 
  from table left join table2 
    on table2.id = table.parent
 where table.parent is null
Chandu
  • 81,493
  • 19
  • 133
  • 134
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
Dave Markle
  • 95,573
  • 20
  • 147
  • 170
0
select id from table inner join table2 on table2.id <> table.parent
Eon
  • 3,833
  • 10
  • 46
  • 75