我想从我的表中删除孤立记录,我有用户和帐户表以及用户帐户映射表。 当我执行下面给出的查询时,它显示语法错误,请帮助。
delete from user_accounts where user_accounts.user_id not in(select user_id from user_accounts ua inner join user u on ua.user_id= u.id);
我得到的错误:
错误代码:1093。您无法指定目标表' user_accounts'用于FROM子句中的更新
答案 0 :(得分:1)
您可以使用简单的left join
delete ua
from user_accounts ua
left join user u on ua.user_id = u.id
where u.id is null
答案 1 :(得分:0)
User
是reserved keyword here,使用`
所以你的查询将是:
delete uac
from user_accounts uac
where uac.`user_id` not in
(select `user_id` from user_accounts ua inner join `user` u on ua.`user_id` = u.id);