同テーブルのサブクエリで値をUPDATEする

More than 1 year has 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;
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.