onedumbcoder Posted January 1, 2009 Share Posted January 1, 2009 lets say i have 10 tables a b c d e f g h i j a has and id the rest have a a_id as afield i want to delete a, and any of the other ones that might exist and have an a_id of the a i am deleting. i do not want to do 10 queries and i cant quite figure out how to use the correct syntax for one query can someone please help me. :'( Link to comment https://forums.phpfreaks.com/topic/139117-how-to-delete-from-multiple-tables-if-some-may-not-exist/ Share on other sites More sharing options...
fenway Posted January 2, 2009 Share Posted January 2, 2009 what do you mean "might not exist".... the tables or the matching values? Link to comment https://forums.phpfreaks.com/topic/139117-how-to-delete-from-multiple-tables-if-some-may-not-exist/#findComment-727873 Share on other sites More sharing options...
onedumbcoder Posted January 2, 2009 Author Share Posted January 2, 2009 the values might not exist Link to comment https://forums.phpfreaks.com/topic/139117-how-to-delete-from-multiple-tables-if-some-may-not-exist/#findComment-727983 Share on other sites More sharing options...
onedumbcoder Posted January 2, 2009 Author Share Posted January 2, 2009 I'm looking for something like this: DELETE FROM a left join b,c,d,e,f WHERE a.id='sdf'=b.aid=c.aid=d.aid=e.aid=f.aid im just looking for the right syntax. i dont want to do this DELETE FROM a WHERE id='asd' DELETE FROM b WHERE aid='asd' DELETE FROM c WHERE aid='asd' DELETE FROM d WHERE aid='asd' DELETE FROM e WHERE aid='asd' DELETE FROM f WHERE aid='asd' Link to comment https://forums.phpfreaks.com/topic/139117-how-to-delete-from-multiple-tables-if-some-may-not-exist/#findComment-728270 Share on other sites More sharing options...
Chicken Little Posted January 3, 2009 Share Posted January 3, 2009 Can you try a cascading delete from the parent table? (i.e. set table structure to allow this) Link to comment https://forums.phpfreaks.com/topic/139117-how-to-delete-from-multiple-tables-if-some-may-not-exist/#findComment-728652 Share on other sites More sharing options...
fenway Posted January 4, 2009 Share Posted January 4, 2009 How about: DELETE a, b, c, d, e, f FROM a left join b on ( a.id=b.aid ) left join c on ( a.id=c.aid ) left join d on ( a.id=d.aid ) left join e on ( a.id=e.aid ) left join f on ( a.id=f.aid ) WHERE a.id='sdf' But I think there might be something wrongwith your table structure. Link to comment https://forums.phpfreaks.com/topic/139117-how-to-delete-from-multiple-tables-if-some-may-not-exist/#findComment-729256 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.