为什么这个复杂的删除SQL查询不起作用?

时间:2018-05-28 09:42:53

标签: mysql sql database rdbms

我正在尝试实现“复杂”的SQL删除查询,但它无法正常工作。

这是我的疑问:

DELETE
FROM Market_Commodity_Price_Series     AS MC_PS
INNER JOIN MarketDetails_CommodityDetails AS MD_CD
      ON MC_PS.market_commodity_details_id = MD_CD.id 
INNER JOIN MarketDetails                     AS MD
      ON  MD_CD.market_details_id = MD.id  
WHERE
      MD.localization_id = 1

我想只删除 Market_Commodity_Price_Series 中的所有行,但是要使用此WHERE条件。正如您可以看到where条件使用某些JOIN操作。

问题是执行此查询我收到此错误消息:

  

#42000您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第2行“AS MC_PS INNER JOIN MarketDetails_CommodityDetails AS MD_CD ON MC_PS.mar”附近使用正确的语法

我该如何解决这个问题?也许使用它作为子查询:

SELECT MC_PS.id
FROM Market_Commodity_Price_Series     AS MC_PS
INNER JOIN MarketDetails_CommodityDetails AS MD_CD
      ON MC_PS.market_commodity_details_id = MD_CD.id 
INNER JOIN MarketDetails                     AS MD
      ON  MD_CD.market_details_id = MD.id  
WHERE
      MD.localization_id = 1

(使用ID)

但是如何?

1 个答案:

答案 0 :(得分:2)

您想删除MC_PS,因此在删除缺少的“MC_PS”后写入

DELETE MC_PS
FROM Market_Commodity_Price_Series     AS MC_PS
INNER JOIN MarketDetails_CommodityDetails AS MD_CD
      ON MC_PS.market_commodity_details_id = MD_CD.id 
INNER JOIN MarketDetails                     AS MD
      ON  MD_CD.market_details_id = MD.id  
WHERE
      MD.localization_id = 1