MYSQL DELETE IN 子查询限制

描述: 如果子查询的 from 子句和更新、删除对象使用同一张表,会出现上述错误。

解决方法: 通过给 from 子句中的结果集起别名。

You can't specify target table 'table' for update in FROM clause

DELETE
FROM
	`table`
WHERE
	id IN (
		SELECT * FROM (
			SELECT
				MAX(id) AS id
			FROM
				`table`
			GROUP BY
				title
			HAVING
				count(*) > 1
		) AS tmp
	);

相关推荐

评论 抢沙发

表情