繁体   English   中英

MYSQL - 根据其他表中的ID值删除行

[英]MYSQL - Delete row based on ID-value in other table

我有2个MySQL表:

Customer_buyings:

BUY_ID   NUMBER   PLANT_ID    CUSTOMER_ID
  001       5         003          009
  002       1         004          009
  003       2         005          010

植物:

PLANT_ID     PLANTNAME
  003          BUXUS
  ...           ...

现在我想删除“customer-buyings”表中的一个特定行。 例如ID为003的工厂。但我的代码中只有Customer_ID和PLANTNAME。

我正在搜索一个MySQL查询,它将根据Customer_id和Plantname从Customer_buyings表中删除第一行(所以我必须将plantname与另一个表中的plant_id进行比较)。

DELETE FROM Customer_buyings
JOIN Plants
ON ...
WHERE ...
AND Customer_id="009"

有什么建议么? 因为我无法理解。

你需要一个合适的连接和一个地方

DELETE c.* FROM Customer_buyings as c
INNER JOIN Plants as p on c.plant_id = p.plant_id
WHERE p.plantname= 'BUXUS'
AND c.Customer_id="009"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM