Jump to content

Deleting across M:M related tables


Recommended Posts

Hey everyone, I am trying to delete across 3 tables without affecting the reliability of the data, but am having a tough time figuring out how. I'm sure there is a standard way of doing this with SQL or the application code (PHP in my case). Here is a short description of my tables:Candidate_table - id_candidate - namePosition_table - id_position - titleRelationship_table - id_position - id_candidate I want to delete the position, and all of the candidates associated with that position. Deleting the Position rows and the Relationship rows are easy:DELETE FROM Position_table WHERE id_position = $id_positionDELETE FROM Relationship_table WHERE id_position = $id_positionBut what is the easiest way to delete the correct candidate from the Candidate_table with only the id_position? For instance, I don't want to delete the candidate if they are assigned to more than one position. Having a hard time wrapping my head around it. Any help would be appreciated.

Edited by jwburnside
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...