title: Stored procedure to update parent in MySQL
body: <p>I have 2 tables for representing sensors and their values:</p>
  
  <pre><code>Unit:
    id
    name
    last_data
  
  Data:
    id
    timestamp
    temperature
    unit
  </code></pre>
  
  <p>So basically I have multiple <code>Data</code> rows for each <code>Unit</code>.</p>
  
  <p>I want to add a SP so every time I insert a <code>Data</code> row, it will automatically update <code>last_data</code> column in the matching parent (to point to the newly create <code>id</code>.</p>
  
  <pre><code>pseudo code:
  
  new_id = INSERT INTO Data (temperature, unit) VALUES (25, 1);
  
  UPDATE Unit SET last_data = new_id WHERE id=1
  </code></pre>
  
  <p>Not sure how to write such procedure...</p>