##同テーブルのとあるカラムの最大+1の値で違うレコードを更新
###エラー
UPDATE hoge_tbl SET val1 = (SELECT MAX(val1)+1 FROM hoge_tbl) WHERE val2 = 10;
###エラー無し
UPDATE hoge_tbl, (SELECT MAX(val1)+1 AS MAX FROM hoge_tbl) A set val1 = A.MAX WHERE val2 = 10;
Go to list of users who liked
More than 5 years have passed since last update.
##同テーブルのとあるカラムの最大+1の値で違うレコードを更新
###エラー
UPDATE hoge_tbl SET val1 = (SELECT MAX(val1)+1 FROM hoge_tbl) WHERE val2 = 10;
###エラー無し
UPDATE hoge_tbl, (SELECT MAX(val1)+1 AS MAX FROM hoge_tbl) A set val1 = A.MAX WHERE val2 = 10;
Register as a new user and use Qiita more conveniently
Go to list of users who liked