Check out example codes for "mysql insert exists update". It will help you in understanding the concepts better.

Code Example 1

INSERT INTO table (column_list)
VALUES (value_list)
ON DUPLICATE KEY UPDATE
   c1 = v1, 
   c2 = v2,
   ...;

Learn ReactJs, React Native from akashmittal.com