bulrush Posted May 19, 2010 Share Posted May 19, 2010 I have a parent table called "group" where the key is an auto increment field called "grid". It is linked to child tables "parts" and "features", which both store the "grid" value in a field called "grid", linking them to the "group" table. How do I find records in the "parts" and "features" tables where the record in "group" (the grid value) no longer exists? (Due to a possible bug, perhaps.) Quote Link to comment https://forums.phpfreaks.com/topic/202278-finding-children-with-no-parents/ Share on other sites More sharing options...
ignace Posted May 19, 2010 Share Posted May 19, 2010 SELECT .. FROM group RIGHT JOIN parts USING (grid) RIGHT JOIN features USING (grid) WHERE group.grid IS NULL Quote Link to comment https://forums.phpfreaks.com/topic/202278-finding-children-with-no-parents/#findComment-1060658 Share on other sites More sharing options...
bulrush Posted May 19, 2010 Author Share Posted May 19, 2010 And so the DELETE statement would be similar, like this? DELETE FROM group RIGHT JOIN parts USING (grid) RIGHT JOIN features USING (grid) WHERE group.grid IS NULL Quote Link to comment https://forums.phpfreaks.com/topic/202278-finding-children-with-no-parents/#findComment-1060677 Share on other sites More sharing options...
ignace Posted May 19, 2010 Share Posted May 19, 2010 Yes. Although before executing you may want to try this on a test database. Quote Link to comment https://forums.phpfreaks.com/topic/202278-finding-children-with-no-parents/#findComment-1060679 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.