title: PHP update MYSQL many-to-many relation
body: <p>I have a many-to-many relation, implemented with an association table in MySQL. I have a table for children and a table for parents. A child can have multiple parents, saved in the parent_child_link association table with their ID's. </p>
  
  <p>Children can be updated through a HTML form, the parents are in a HTML multi-select. Now I need to update the record in the database, but my solution is not very efficient. Here's in pseudocode what I do:</p>
  
  <ol>
  <li>Update the child information where child_id=x</li>
  <li>Delete all the current associations in parent_child_link where child_id=x</li>
  <li>Insert the new associations</li>
  </ol>
  
  <p>This solution works great, but when the the parents weren't changed, e.g. only the name of the child was changed, then there are 2 unnecessary queries executed. How can I avoid those unnecessary queries? Is there some way to check if the parents in the multi-select didn't change?</p>
  
  <p>Ofcourse I could just ignore all this hassle, because it already works, but I really like to keep things as efficient as possible.</p>