title: MySQL: Get last update id from a table to insert it in an other table
body: <p>basically I'm trying to update a table and in case of something changed to save the unique id of the changed row in an other table (with some other informations). </p>
  
  <p>it's almost the same principle as LAST_INSERT_ID() but for update not insert. I searched in Internet and the best what i got is this statement:</p>
  
  <pre><code>SET @update_id := NULL;
  UPDATE friendships SET status = ?, id = (SELECT @update_id := id) 
         WHERE (from_user = ? AND to_user = ?) OR (to_user = ? AND from_user = ?);
  INSERT INTO actions(user_id, code, foreign_id) VALUES(?, ?, SELECT @update_id);
  </code></pre>
  
  <p>all this statment is passed all together to a PDO prepare execute function. i don't have an error back but i have the first table updated and nothing inserted in the second.</p>
  
  <p>@update_id is supposed to hold the id of the changed row in the first query to be used in the second one. </p>
  
  <p>i can't use a trigger on the first table to update automatically the second because i have  to insert the "code" in the second table and can't pass it in the first query (since it's not used or inserted in the first table).</p>
  
  <p>tried my best to explain the situation.. hope u understand me and can help me too</p>
  
  <p>much thank in advance</p>