title: Insert into a MySQL table or update if exists
body: <p>I want to add a row to a database table, but if a row exists with the same unique key I want to update the row.</p>
  <p>For example:</p>
  <pre class="lang-sql prettyprint-override"><code>INSERT INTO table_name (ID, NAME, AGE) VALUES(1, &quot;A&quot;, 19);
  </code></pre>
  <p>Let’s say the unique key is <code>ID</code>, and in my <strong>Database</strong>, there is a row with <code>ID = 1</code>. In that case, I want to update that row with these values. Normally this gives an error.<br />
  If I use <code>INSERT IGNORE</code> it will ignore the error, but it still won’t update.</p>