Jump to content

Deleting across M:M related tables


justinbriggs1

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.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...