-1

I am trying to perform this SQL DELETE query that involves some INNER JOIN. I want delete only from the main table named Market_Commodity_Price_Series. I am using MySql.

This is my query:

DELETE
FROM Market_Commodity_Price_Series AS MCPS
INNER JOIN MarketDetails_CommodityDetails AS MDCD
      ON MCPS.market_commodity_details_id = MDCD.id
INNER JOIN MarketDetails AS MD
      ON MDCD.market_details_id = MD.id
WHERE MD.market_name = "Kimironko"

The problem is that performing this query I obtain the following 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 'MCPS INNER JOIN MarketDetails_CommodityDetails AS MDCD ON MCPS.market_co' at line 2

The "strange" thing is that the SELECT * version of this query works fine, I obtain the records that I expect.

I want to use the delete version to delete these records only from the main query specified by the FROM clause.

What is wrong? What am I missing? How can I fix this error?

Giorgos Betsos
  • 71,379
  • 9
  • 63
  • 98
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596

1 Answers1

2

You need to specify from which table you want the record to be deleted: (Note the table alias after DELETE)

DELETE MCPS
FROM Market_Commodity_Price_Series AS MCPS
INNER JOIN MarketDetails_CommodityDetails AS MDCD
      ON MCPS.market_commodity_details_id = MDCD.id
INNER JOIN MarketDetails AS MD
      ON MDCD.market_details_id = MD.id
WHERE MD.market_name = "Kimironko"
dognose
  • 20,360
  • 9
  • 61
  • 107