我正在尝试触发以下查询...
有什么问题吗?
delete from user_role
WHERE user_id in (
select u.user_id from user u, user_role ur
where u.USER_ID=ur.USER_ID and ur.ROLE_ID=4 and u.USER_ID not in (
select user_id from referrers));
最佳答案
如手册部分所述DELETE
Syntax :
Currently, you cannot delete from a table and select from the same table in a subquery.
您可以改为使用 DELETE
和 join 的多表形式把你的 table 放在一起:
DELETE user_role
FROM user_role
INNER JOIN user_id USING (USER_ID)
LEFT JOIN referrers USING (USER_ID)
WHERE user_role.ROLE_ID = 4 AND referrers.USER_ID IS NULL
关于mysql - 查询中有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11339368/