关于MySQL中删除满足子查询结果数据的操作

关于MySQL中删除满足子查询结果数据的操作

关键问题:MySQL不允许在子查询中使用要删除的表

错误示范:

DELETE
FROM
post_activity_user
WHERE
id IN (
SELECT
	a.id
FROM
	post_activity_user a
LEFT JOIN post_activity_info b ON a.activity_id = b.id
WHERE
	b.enterprise_id = 10000000
AND b.activity_type = 3
)

正确处理:

DELETE
FROM
	post_activity_user
WHERE
	post_activity_user.id IN (
		SELECT
			*
		FROM
			(
				SELECT
					a.id
				FROM
					post_activity_user a
				LEFT JOIN post_activity_info b ON a.activity_id = b.id
				WHERE
					b.enterprise_id = 10000000
				AND b.activity_type = 3
			) ee
	)
posted @ 2019-03-01 21:04  余不见  阅读(7678)  评论(1编辑  收藏  举报