title: Running a MySQL Insert when update fails
body: <p>What is the fastest approach to update a row and if the parameters don't exist insert it.</p>
  
  <p>My table has 2 columns for ids <code>quote_id, order_id</code> and those columns combined would make a unique column. I don't want 2 rows containing the same <code>quote_id</code> and <code>order_id</code> but either can have multiple rows.</p>
  
  <pre><code>id | quote_id | order_id
  1  | q200     | o100
  2  | q200     | o101
  3  | q201     | o100
  </code></pre>
  
  <p>Previously I would have added a third field and combined those 2 fields with a <code>-</code> so I could use the <code>ON DUPLICATE KEY UPDATE</code>. But this is not very efficient as I seem to forget to add those fields sometimes.</p>
  
  <p>My idea is to try to run the update query and if it fails the insert it as I run a lot more update queries then insert. How would I put this into a single query instead of the MySQL server having to return a error and then I rerun the insert query.</p>
  
  <p><code>if (
     UPDATE table_name SET column1=value, column2=value2 WHERE some_column=some_value === ERROR
  ) THEN 
     INSERT INTO table_name ....</code></p>
  
  <p>I looked through some of the MySQL documentation and I couldn't find a example that showed how an error is detected in a <code>IF</code> statement</p>