vendredi 26 juin 2015

MYSQL, ON DUPLICATE UPDATE and IF

My query look actually to :

INSERT INTO `table` (f1,f2,status) VALUES 
(1,5,'on'),  (3,2,'on'), (15,20,'on') 
ON DUPLICATE KEY UPDATE status='off';

But how to add IF status="on" then do this update ? I tried

INSERT INTO `table` (f1,f2,status) VALUES 
(1,5,'on'),  (3,2,'pending'), (15,20,'on') 
ON DUPLICATE KEY UPDATE status='off' IF(status='pending');

But seems doesn't work, I didn't understand well this part in documentation.

Any help please?

Thanks

Aucun commentaire:

Enregistrer un commentaire