我有两张桌子:
tickets
tickets_updates
我认为在表tickets_updates
中不存在记录的地方有一些额外的行tickets
运行 SQL 代码的最佳方式是什么?
删除所有不在的tickets_updates
地方(序列)ticket_seq
tickets
门票表中的序列与门票更新表中的门票序列匹配
DELETE FROM tickets_updates
WHERE ticket_seq NOT IN (SELECT sequence
FROM tickets)
DELETE FROM tickets_updates tu
LEFT JOIN tickets t ON tu.ticket_seq = t.sequence
WHERE t.sequence IS NULL
试试这个:
DELETE FROM ticket_updates
WHERE NOT EXISTS
(SELECT 'x' from tickets
WHERE tickets.sequence = ticket_updates.ticket_seq)