问题描述
我正在尝试在 MySQL 中执行以下查询
I am trying to execute below query in 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))
并得到以下错误:
Query: Delete from zc_products zcp where zcp.products_id in (SELECTDISTINCT p.products_id as pid FROM zc_products p, zc_products_to_ca...
错误代码:1064 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册在'zcp where zcp.products_id in (SELECT DISTINCT)附近使用的语法p.products_id 作为 pid FROM zc_prod' 在第 1 行
Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'zcp where zcp.products_id in (SELECT DISTINCT p.products_id as pid FROM zc_prod' at line 1
我正在尽一切努力解决这个问题,但没有运气.
I am trying everything to fix this but no luck.
请其他人帮助我.
推荐答案
您的 SQL
语句中有一个 unexpected identifier
... 这是因为您正在使用alias
zcp 不必要的.使用您拥有的 SQL
,无需在 DELETE
子句中对 table
进行别名
.>
You have an unexpected identifier
in your SQL
statement ... This is because you are using the alias
zcp unnecessarily. With the SQL
that you have, there is no need to alias
the table
in the DELETE
clause.
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 之类的工具 - 它会为您识别问题...让您更轻松地进行故障排除.
NOTEIf you used a tool like MySQL Workbench -- It would identify the problem for you ... Allowing you to troubleshoot more easily.
这篇关于MySQL 查询错误(SQL 语法错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!