mysql数据库中有三个表:
orders: order_sequence_number, contact_id, date_ordered ...
orderdetail: order_sequence_number ...
person: contact_id ...
我试图删除三个表中日期顺序值早于两年的所有行,但是日期顺序字段只出现在orders表中,但是该表通过order序列号和contact id字段链接到另外两个表。
所以,我想有点像这样:…
SELECT * FROM orders WHERE date_ordered BETWEEN X AND Y
然后用那套唱片
DELETE FROM orderdetail WHERE orderdetail.order_sequence_number IN (THE ABOVE)
等人餐桌…但是没有运气。
在我看来像是某种嵌套的子查询,但我很难理解如何进行这样的查询,无法理解它的复杂性质…
任何指点都非常感谢。
最佳答案
DELETE FROM orderdetail
WHERE order_sequence_number IN
(
SELECT id
FROM orders
WHERE date_ordered BETWEEN X AND Y
)