[英]PHP Delete rows from MySQL where two tables don't match
I have two tables: 我有两个表:
tickets
tickets_updates
I think there are a few extra rows in tickets_updates
where a record doesn't exist in the tickets
table 我认为
tickets_updates
中还有一些额外的行,而tickets
表中不存在记录
What is the best way to run SQL Code to say: 运行SQL代码的最佳方式是:
Delete all from tickets_updates
where ticket_seq
is not in tickets
(sequence) 从
tickets_updates
中删除ticket_seq
不在tickets
所有tickets
(顺序)
sequence in the tickets table matches ticket_seq in the tickets_updates table 票证表中的序列与tickets_updates表中的ticket_seq匹配
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
Try this: 尝试这个:
DELETE FROM ticket_updates
WHERE NOT EXISTS
(SELECT 'x' from tickets
WHERE tickets.sequence = ticket_updates.ticket_seq)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.