Update data using IF in mysql and define 'dont do anything' when if false

前端 未结 2 2053
天命终不由人
天命终不由人 2021-01-23 23:41

Im trying to use IF query in update some entire row in my mysql table. As known IF query have 3 parameters. Part 1 of what you looking for, part 2 if its found / true and part 3

2条回答
  •  遥遥无期
    2021-01-24 00:24

    You're confusing an update with a condition with a conditional update. For example the following is an update with a condition:

    UPDATE x SET y=IF(a=b, c, d)
    

    This is a conditional update:

    UPDATE x SET y=c WHERE a=b
    

    The first version is applied to all rows, the second to all matching rows.

    Use a WHERE clause to limit what rows your UPDATE is applied to.

提交回复
热议问题