mysql - On Duplicate Key Update insert record every time -
i'm using mysql query
insert table (vin,name,city,dob) values ('der12','john','city name','2016-17-10') on duplicate key update name='john'
table structure
id - bigint -primary key vin - varchar name - varchar city - varchar dob - varchar
so here have id bigint , autoincreament , , vin can't duplicate , need check if vin in table , update record or nothing if same , if vin diffrent insert record.
i tried making vin unique as
alter table table add unique (vin)
but problem after adding when run query shows duplicacy error instead of updating or ignoring .
need kind .
thanks in advance
from understood, want add record if "vin" different else keep previous record is.
you can count of records having "vin" "john" or value inserting currently. if count "0", insert record else nothing.
Comments
Post a Comment