# Mysql报错ERROR 1093

update monitor set Endtime = "10:01:13"
where Id =
(select max(Id) from monitor  where Portaljid = "portal" and Pathid = "path_A" )


ERROR 1093 (HY000): You can't specify target table 'A' for update in FROM clause


In general, you cannot modify a table and select from the same table in a subquery. For example, this limitation applies to statements of the following forms:
DELETE FROM t WHERE ... (SELECT ... FROM t ...);
UPDATE t ... WHERE col = (SELECT ... FROM t ...);
{INSERT|REPLACE} INTO t (SELECT ... FROM t ...);

Exception: The preceding prohibition does not apply if you are using a subquery for the modified table in the
FROM
clause. Example:
UPDATE t ... WHERE col = (SELECT (SELECT ... FROM t...) AS _t ...);
Here the prohibition does not apply because a subquery in the FROM clause is materialized as a temporary table, so the relevant rows in    t have already been selected by the time the update to    t takes place.


update monitor set Endtime = "10:01:13"
where Id =
(select max(temp.id) from (select m.id from monitor m) temp where Portaljid = "portal" and Pathid = "path_A")