Advertisement
obernardovieira

CASE or IF or WHERE inside UPDATE

Jan 25th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.27 KB | None | 0 0
  1. UPDATE `table_name`
  2. SET `var`=1
  3. WHERE `condition`='value' AND `var`=0
  4.  
  5. //or
  6.  
  7. UPDATE `table_name`
  8. SET `var`= CASE
  9. WHEN `var`=0 THEN 1
  10. ELSE `var`
  11. END
  12. WHERE `condition`='value'
  13.  
  14. //or
  15.  
  16. UPDATE `table_name`
  17. SET `var`= IF(`var`=0,1,`var`)
  18. WHERE `condition`='value'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement