26
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

##同テーブルのとあるカラムの最大+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;
26
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?