このページの2つのバージョン間の差分を表示します。
— | 02_freebsd:04_database:01_mysql:11_error_1093 [2015/03/27 08:57] (現在) – 作成 matsui | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== 11 ERROR: | ||
+ | update の時同じテーブルに対するサブクエリからの操作ができない | ||
+ | |||
+ | <code console> | ||
+ | update hoge set code = 0 | ||
+ | where id IN | ||
+ | (select id from hoge as tmp where id = 1 group by id order by id) | ||
+ | ; | ||
+ | |||
+ | ERROR 1093 (HY000): You can't specify target table ' | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== 対応 ===== | ||
+ | |||
+ | これで上手くいく | ||
+ | <code console> | ||
+ | update hoge set code = 0 | ||
+ | where id IN ( | ||
+ | select id from | ||
+ | (select id from hoge where id = 1 group by id order by id) as tmp | ||
+ | ) | ||
+ | ; | ||
+ | </ |