title: MySQL procedure with insert and update
body: <p>I need some help to create a procedure in MySQL.</p>
  
  <p>I have two tables:</p>
  
  <ol>
  <li>connection</li>
  <li>connection_temporary</li>
  </ol>
  
  <p>And I want to create a procedure that does:</p>
  
  <ul>
  <li>If <code>SELECT keyname FROM connection WHERE keyname NOT IN (SELECT keyname FROM connection_temporary)</code> <strong><em>update connection.connection_status to offline</em></strong></li>
  <li>If <code>SELECT keyname FROM connection_temporary WHERE keyname NOT IN (SELECT keyname FROM CONNECTION)</code> <strong><em>insert in connection with connection_temporary's row content</em></strong></li>
  <li>If <code>SELECT keyname, real_ip, virtual_ip, received_bytes, sent_bytes, connection_tstamp FROM connection_temporary WHERE keyname IN (SELECT keyname FROM CONNECTION)</code> <strong><em>update connection with connection_temporary's row content</em></strong></li>
  </ul>
  
  <p>How can I do this?</p>