title: MySQL update record if two columns match data, otherwise insert row
body: <p>I have a simple MySQL table with three columns: "id" (INT), "property" (VARCHAR) and "value" (VARCHAR).</p>
  
  <p>All the columns have to be able to have identical records (i.e. several records with the same id).</p>
  
  <p>The ideas is to save different properties matching different ids.</p>
  
  <p>My question is, how would I go about updating a record if my data matches both the ID and the Property, and otherwise add a new record?</p>
  
  <p>I initially thought about using the <code>ON DUPLICATE KEY</code>, but that won't work, as none of my columns are unique.</p>
  
  <p><strong>Here's an example of the desired behavior:</strong></p>
  
  <p>1: I start with this table:</p>
  
  <pre><code>+----+----------+-------+
  | id | property | value |
  +----+----------+-------+
  | 45 | money    |   500 |
  +----+----------+-------+
  </code></pre>
  
  <p>2: I then insert: <code>id = 45, property = sex, value = male</code>, and I get:</p>
  
  <pre><code>+----+----------+-------+
  | id | property | value |
  +----+----------+-------+
  | 45 | money    | 500   |
  | 45 | sex      | male  |
  +----+----------+-------+
  </code></pre>
  
  <p>3: I then insert: <code>id = 45, property = money, value = 600</code>, and I get:</p>
  
  <pre><code>+----+----------+-------+
  | id | property | value |
  +----+----------+-------+
  | 45 | money    | 600   |
  | 45 | sex      | male  |
  +----+----------+-------+
  </code></pre>
  
  <p>4: Lastly, I can do this: <code>id = 46, property = money, value = 600</code>, and get:</p>
  
  <pre><code>+----+----------+-------+
  | id | property | value |
  +----+----------+-------+
  | 45 | money    | 600   |
  | 45 | sex      | male  |
  | 46 | money    | 600   |
  +----+----------+-------+
  </code></pre>