title: MySQL ON DUPLICATE KEY UPDATE for multiple rows insert in single query
body: <p>I have a SQL query where I want to insert multiple rows in single query. so I used something like:</p>
  
  <pre><code>$sql = "INSERT INTO beautiful (name, age)
    VALUES
    ('Helen', 24),
    ('Katrina', 21),
    ('Samia', 22),
    ('Hui Ling', 25),
    ('Yumie', 29)";
  
  mysql_query( $sql, $conn );
  </code></pre>
  
  <p>The problem is when I execute this query, I want to check whether a <code>UNIQUE</code> key (which is not the <code>PRIMARY KEY</code>), e.g. <code>'name'</code> above, should be checked and if such a <code>'name'</code> already exists, the corresponding whole row should be updated otherwise inserted. </p>
  
  <p>For instance, in the example below, if <code>'Katrina'</code> is already present in the database, the whole row, irrespective of the number of fields, should be updated. Again if <code>'Samia'</code> is not present, the row should be inserted.</p>
  
  <p>I thought of using:</p>
  
  <pre><code>INSERT INTO beautiful (name, age)
        VALUES
        ('Helen', 24),
        ('Katrina', 21),
        ('Samia', 22),
        ('Hui Ling', 25),
        ('Yumie', 29) ON DUPLICATE KEY UPDATE
  </code></pre>
  
  <p>Here is the trap. I got stuck and confused about how to proceed. I have multiple rows to insert/update at a time. Please give me a direction. Thanks.</p>