MySQL can’t specify target table for update in FROM clause

 翻译:MySQL不能指定更新的目标表在FROM子句

 源SQL语句:

 

update trust_product set product_state='1' where id=(select max(id) frrom  trust_product)

 

执行报以下错误:

[SQL]update trust_product set product_state='1' where id=(select max(id) from  trust_product)

[Err] 1093 - You can't specify target table 'trust_product' for update in FROM clause

 解决代码如下:

UPDATE trust_product
SET product_state = '1'
WHERE
	id = (
    select id from (
		SELECT
			MAX(id)
		FROM
			trust_product 
	) AS temtable);

 

 

分析:

先把要删除的目标放到一张临时表再把要删除的条件指定到这张临时表即可。

posted on 2016-03-16 18:54  @ 小浩  阅读(257)  评论(0编辑  收藏  举报