今天遇到的问题,随口说一句。
MySQL 中,如果 update 语句中含有 select 子句,那么update 的表和 select 子句中的表不能是一个。否则会得到“You can't specify target table ‘<Table Name>’ for update in FROM clause” 的错误消息。解决方法是在 select 子句的 from 不直接用表名,而是用一个另外一个 select 语句得到一个临时表。
update <Table Name> set xxx=xxx where
(
select * from (select tmp.* from <Table Name> tmp) a
where something
) = something