tags:

views:

36

answers:

1

Hi, basically want to have a multiple update based on a few conditions. So this is my sql query which returns error:

Table have 3 columns: user_id, week and change

INSERT INTO rank (user_id, week) VALUES (364709193,'201042'),(291179703,'201042'),(394613472,'201042'),(284220417,'201042'),(395465205,'201042'),(394807905,'201042'),(293778748,'201042'),(327814326,'201042'),(370339723,'201042'),(372836496,'201042'),(368162484,'201042'),(304075989,'201042'),(326916014,'201042'),(322410766,'201042'),(395317832,'201042'),(293338707,'201042'),(375562663,'201042'),(325955444,'201042'),(386657944,'201042'),(360475871,'201042'),(299852753,'201042'),(335498887,'201042'),(290629277,'201042'),(376948520,'201042'),(331975235,'201042'),(304878510,'201042'),(284882215,'201042'),(284815942,'201042'),(300048137,'201042')

ON DUPLICATE KEY UPDATE change='new',change='-4',change='new',change='new',change='new',change='new',change='new',change='new',change='new',change='new',change='new',change='new',change='+1',change='new',change='new',change='new',change='new',change='new',change='new',change='new',change='new',change='new',change='0',change='new',change='new',change='new',change='+18',change='new',change='new' ;

Anyone have any idea? :D

A: 

How about:

REPLACE INTO `rank` (`user_id`,`week`,`change`) VALUES (364709193,'201042','new),(291179703,'201042','new'), ... etc.

If this doesn't do what you need, post your error message, or more details about what you are trying to do.

David Jones
Keep in mind, replace works like doing a delete and then an insert. With myisam, this can waste disk space if your not running table checks and optimizes regularly. If your using innodb and have a cascade on delete setup for any of the columns in this table, replace will trigger it.
txyoji