missyevil Posted April 1, 2006 Share Posted April 1, 2006 Hi, this is probably a really simple problem, but I can't seem to get the syntax for the command right!I'm trying to delete related entries in 2 MySQL tables simultaneously. What I'm trying looks like this:[code]DELETE FROM cvs, jscvs WHERE cvid = '$cvid'[/code]Where cvs and jscvs are the two tables, and cvid is the primary key in each.When I run it tho, I get an error, and nothing is deleted.Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/6337-deleting-related-entries-in-multiple-tables/ Share on other sites More sharing options...
fenway Posted April 1, 2006 Share Posted April 1, 2006 Try the following (UNTESTED):[code]DELETE cvs.*, jscvs.* FROM cvs, jscvs WHERE cvid = '$cvid'[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6337-deleting-related-entries-in-multiple-tables/#findComment-22924 Share on other sites More sharing options...
Zane Posted April 1, 2006 Share Posted April 1, 2006 This could work as wellit will delete every key that has a matching one in the other table...leaving the 'unrelated' onesas I assume you wanted[code]DELETE FROM cvs, jscvs USING cvs, jscvs WHERE cvs.id = jscvs.id;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6337-deleting-related-entries-in-multiple-tables/#findComment-22933 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.