MySQL Query中的错误(SQL语法中的错误)

时间:2018-02-01 16:47:00

标签: mysql

我正在尝试在MySQL中执行以下查询

DELETE FROM zc_products zcp 
WHERE zcp.products_id IN (SELECT DISTINCT p.products_id FROM zc_products p, zc_products_to_categories pc WHERE 
p.products_id = pc.products_id AND 
pc.categories_id IN (SELECT DISTINCT zcc.categories_id FROM zc_categories zcc WHERE zcc.categories_status = 0))

并低于错误:

  

查询:从zc_products zcp中删除zcp.products_id in(SELECT   DISTINCT p.products_id as pid FROM zc_products p,zc_products_to_ca ...

     

错误代码:1064您的SQL语法出错;检查   与您的MariaDB服务器版本对应的手册   在'zcp中使用zcp.products_id附近的语法(SELECT DISTINCT   p.products_id为第1行的pid FROM zc_prod'

我正在努力解决这个问题,但没有运气。

请求其他人帮助我。

1 个答案:

答案 0 :(得分:0)

您的unexpected identifier声明中有SQL ...这是因为您不必要地使用alias zcp 。使用SQL,您无需在alias子句中table DELETE

DELETE FROM zc_products
WHERE products_id IN (SELECT DISTINCT p.products_id FROM zc_products p, zc_products_to_categories pc WHERE 
p.products_id = pc.products_id AND 
pc.categories_id IN (SELECT DISTINCT zcc.categories_id FROM zc_categories zcc WHERE zcc.categories_status = 0));

注意 如果您使用像MySQL Workbench这样的工具 - 它会识别 的问题...允许您更轻松地进行故障排除。