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.) 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 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 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. 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
Archived
This topic is now archived and is closed to further replies.