Jump to content


Deleting related entries in multiple tables

  • Please log in to reply
2 replies to this topic

#1 missyevil

  • Members
  • PipPip
  • Member
  • 21 posts

Posted 01 April 2006 - 04:21 PM

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:

DELETE FROM cvs, jscvs WHERE cvid = '$cvid'

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?

#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 01 April 2006 - 06:22 PM

Try the following (UNTESTED):

DELETE cvs.*, jscvs.* FROM cvs, jscvs WHERE cvid = '$cvid'

Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 Zane

  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 01 April 2006 - 06:53 PM

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

DELETE FROM cvs, jscvs USING cvs, jscvs WHERE cvs.id = jscvs.id;

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users