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)... Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.