考虑到这些模式订单(订单号,已创建,状态)产品(产品id,产品名称)订单产品(订单号,产品id,数量)如果我想删除超过n天的订单,我还必须删除订单产品表中与这些订单相关的记录。如何在单个查询中实现这一点,而不必检索每个订单号,将它们存储在业务逻辑中,最后运行其他查询来清理Map表?我没有fk
k10s72fa1#
这似乎奏效了:
DELETE orders_products, orders FROM orders_products INNER JOIN orders ON orders_products.order_number = orders.order_number WHERE orders.created < NOW() - INTERVAL 30 DAY
1条答案
按热度按时间k10s72fa1#
这似乎奏效了: