title: MySQL - prevent duplicates for multiple insert statement without using a unique index
body: <p>I need to do a multiple insert statement and I need to prevent duplicate rows <strong>without using the primary key or any other unique index</strong>. The to-be-inserted rows need to check two (or more) columns for equality, then prevent the insert if all columns match at least one row already within the table. The ideal solution would be to only use one MySQL insert statement.</p>
  
  <p>For example, there is a table with one row already inserted:</p>
  
  <pre><code>INSERT INTO `table1` (`a`, `b`, `c`)
    VALUES ('1', '2', 'foo');
  </code></pre>
  
  <p>This is the data that still needs to be inserted:</p>
  
  <pre><code>INSERT INTO `table1` (`a`, `b`, `c`)
    VALUES ('A', 'B', 'C'), ('1', '2', 'bar'), ('D', 'E', 'F');
  </code></pre>
  
  <p>How can you check columns a and b for duplicates so that ('1', '2', 'bar') does not get inserted while both ('A', 'B', 'C') and ('D', 'E', 'F') do get inserted?</p>