sql - Mysql insert into duplicate key on a non-duplicate key -


i use php , mysql.

this sql works:

insert products (id, title, description)             values (10, 'value1', 'value2')             on duplicate key update             id=10,             title='value25',             description='value2' 

my id primary key , therefor works. other fields varchars.

my real case bit different. @ this:

type introduced , together sku it's unique.

id    sku    title    description    type 1     abc                            1 2     abc                            2 3     def                            1 

so "real" key sku want use , it's not unique own. can not in case. type unique.

look below , might more clear:

abc-one // unique combination abc-two // unique combination def-one // unique combination 

is possible use multi insert/update sql query in case?

if define columns sku , type unique columns, on duplicate key update expression work e.g. 1 primarykey in products table.

example (based on data):

id    sku    title    description    type 1     abc                            1 2     abc                            2 3     def                            1  //insert insert products (id, sku, type) values (4, 'ghi', 'one') on duplicate key update ...   //update dataset id=1 insert products (id, sku, type) values (1, 'ghi', 'two') on duplicate key update ...   //update dataset sku='abc' , type='one' insert products (id, sku, type) values (5, 'abc', 'one') on duplicate key update ...  

therefore see mysql documentation: https://dev.mysql.com/doc/refman/5.5/en/insert-on-duplicate.html


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -