Jump to content

Archived

This topic is now archived and is closed to further replies.

missyevil

Deleting related entries in multiple tables

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Try the following (UNTESTED):

[code]DELETE cvs.*, jscvs.* FROM cvs, jscvs WHERE cvid = '$cvid'[/code]

Share this post


Link to post
Share on other sites
This could work as well

it will delete every key that has a matching one in the other table...leaving the 'unrelated' ones
as I assume you wanted

[code]
DELETE FROM cvs, jscvs USING cvs, jscvs WHERE cvs.id = jscvs.id;[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.