guyfromfl Posted February 23, 2010 Share Posted February 23, 2010 What is the best way to remove rows from one table that does not have children in another table? I want to go through all the table1 entries and if table2.table1id does not return anything, then delete table1's entry table1: id <misc data> table2: id table1id <misc data> So what I need is something like DELETE FROM table1 where < COUNT(SELECT * FROM table1id) = 0 Another way to say it is I want to delete all the orders (table1) that do not have any line items (table2)... Link to comment https://forums.phpfreaks.com/topic/193085-delete-a-row-that-does-not-have-child-rows/ Share on other sites More sharing options...
fenway Posted February 24, 2010 Share Posted February 24, 2010 A LEFT JOIN .. is NULL should suffice. Link to comment https://forums.phpfreaks.com/topic/193085-delete-a-row-that-does-not-have-child-rows/#findComment-1017641 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.