我想根据我从其他查询中获得的记录删除一些记录。问题是我有语法错误,我无法解决。
以下是我正在使用的查询:
DELETE FROM `tickets` as c
WHERE c.TICKET_ID IN ( SELECT a.TICKET_ID
FROM `tickets` as a
INNER JOIN `old_tickets` as b
ON b.TICKET_ID = a.TICKET_ID);
答案 0 :(得分:1)
为什么你需要IN子句,只需加入
即可delete c from tickets c
join old_tickets oc on oc.TICKET_ID = c.TICKET_ID
答案 1 :(得分:0)
试试这个
DELETE FROM tickets as a
INNER JOIN old_tickets as b ON b.TICKET_ID = a.TICKET_ID
答案 2 :(得分:0)
你必须删除子查询中的Join,无论如何你要检查来自ticket1的所有TICKET_ID,它们在old_tickets表中有匹配;
以便您的查询变为:
DELETE FROM tickets t1
WHERE t1.TICKET_ID IN (SELECT t2.TICKET_ID
FROM old_tickets t2)