Sometimes data operations are required, and data is updated if there is data, and no data is inserted. The previous practice is to query, and then based on the query results to judge, to perform the INSERT or update operation
There is actually an on DUPLICATE KEY UPDATE syntax that allows you to do this in one SQL.
INSERT into Tbprize (Sopenid,iareaid,iplatid,sssgroupone,sssgrouptwo,ssgroupone,ssgrouptwo,sgroupone,sgrouptwo, Dtfound) VALUES (' 2a4528699714bc8016daed06e245163f ', 1038,1038,556175,556172,111,222,556144,556137, ' 2018-03-20 11:28:30 ')
On DUPLICATE KEY UPDATE sopenid = ' 2a4528699714bc8016daed06e245163f ', ssgroupone=777,ssgrouptwo=888
- Added after normal INSERT statement, on DUPLICATE KEY UPDATE Field name = value, multiple values comma separated
- Must have a primary key or a unique key, the optional statement does not take effect
MySQL insert update on a SQL on DUPLICATE KEY update