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

时间:2022-09-15 18:28:43

I am trying to implement a "complex" SQL delete query but it is not working.

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

This is my query:

这是我的查询:

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

I want to delete all the rows only from the Market_Commodity_Price_Series but with this WHERE condition. As you can see the where condition use some JOIN operation.

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

The problem is that performing this query I am obtaining this error message:

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

#42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS MC_PS INNER JOIN MarketDetails_CommodityDetails AS MD_CD ON MC_PS.mar' at line 2

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

How can I fix this? Maybe using this as sub query:

我怎样才能解决这个问题?也许使用这个作为子查询:

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

(using the ID)

(使用ID)

but how?

1 个解决方案

#1


2  

You want to delete MC_PS so write it after delete "MC_PS" which is missing

您想要删除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

#1


2  

You want to delete MC_PS so write it after delete "MC_PS" which is missing

您想要删除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