MYSQL Check for duplicates and only insert if another field is a certain value -
if i'm inserting data table following fields:
serialnumber active country
i need insert duplicate serialnumbers if active no.
so example: want insert record serialnumber 1234.
if serial number doesn't exist in table go ahead , add it. if exist, check value of 'active' active yes don't add new record, if it's no add record.
any ideas how achieve in mysql?
you can use on duplicate key statement after insert query update row if exists. documentation : https://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
insert table (serialnumber , active, country) values (1010, 'no', 'fr') on duplicate key update active='yes';
Comments
Post a Comment