我试图从表A中删除其中ID存在于包含表A的Select Inner Join中,类似于:
Delete from TableA where ID in
(Select Distinct A.ID from TableA A
Inner Join TableC C
Inner Join TableJ J
Inner Join Table J J2
On J.VendorID=J2.VendordID
and J.Title=J2.Title
and A.C_ID=C.C_ID
and J.ID=A.J_ID
and J2.ID=C.J_ID)
Select就像我想要的那样(令人惊讶),但我一直收到错误
1093 - You can't specify target table 'TableA' for update in FROM clause
我认为这意味着您无法尝试从子查询中包含的表中删除。反正有没有重组这个我可以吗?
答案 0 :(得分:1)
您不需要使用子查询。
Delete A from TableA A
Inner Join TableC C
Inner Join TableJ J
Inner Join TableJ J2
On J.VendorID = J2.VendordID
and J.Title = J2.Title
and A.C_ID = C.C_ID
and J.ID = A.J_ID
and J2.ID = C.J_ID