title: insert into mysql database, if records already exists, then update
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1218905/how-do-i-update-if-exists-insert-if-not-aka-upsert-or-merge-in-mysql">How do I update if exists, insert if not (aka upsert or merge) in MySQL?</a>  </p>
  </blockquote>
  
  
  
  <p>how to insert into mysql database, if records already exists, then update...I know there is a solution on this page:
  <a href="http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html</a></p>
  
  <p><strong>sib_table</strong></p>
  
  <pre><code>+=======================================================+
  | sib_id | std_id  |  sib_name  |  sib_sex  |  sib_age  |
  +=======================================================+
  | 1      | 77      |  Sajjad    |   m       | 5/17/1990 |
  | 1      | 77      |  Farah     |   f       | 9/14/1980 |
  | 1      | 77      |  Bilal     |   m       | 1/10/1995 |
  +=======================================================+
  </code></pre>
  
  <p>What sql would be if I want to add anther sibling to this table.</p>
  
  <pre><code>INSERT INTO sib_table
    (std_id,sib_name,sib_sex,sib_age) 
  VALUES ('77','Sajjad','m','1/5/2010')  
  ON DUPLICATE KEY 
    UPDATE id = LAST_INSERT_ID(id), c = 3;
  
  INSERT INTO sib_table
    (std_id,sib_name,sib_sex,sib_age) 
  VALUES 
    ('77','Aamna','f','1/27/2005')  
  ON DUPLICATE KEY 
    UPDATE id = LAST_INSERT_ID(id), c = 3;
  </code></pre>