Thursday, June 3, 2010

Finding all orphaned records where there are multiple parent tables and columns

Finding all orphaned records where there are multiple parent tables and columns;

select id from addresses where id not in (select * from ((select address_id as 'id' from orders) union (select shipping_address_id as 'id' from orders) union (select address_id as 'id' from customers) union (select shipping_address_id as 'id' from customers) order by id) as ui);

No comments:

Post a Comment