MySQL 子查询不工作,生成错误代码 1064
该查询不起作用
SELECT * FROM Catalogue WHERE Catalogue.ID IN (
SELECT ID_catalogue FROM Categories WHERE Categories.Product_type='xxx'
)
错误代码:1064 你有一个错误 你的 SQL 语法靠近 'SELECT ID_catalogue 来自类别 WHERE Categories.Product_type='xxx') ' 在 第 2 行
行 好的,那是因为我使用的是非常旧的 MySQL 版本。
我想要得到的是
SELECT * FROM Catalogue WHERE Product_type='xxx' OR Catalogue.ID IN (
SELECT ID_catalogue FROM Categories WHERE Categories.Product_type='xxx'
)
有没有同等的东西?
感谢您的所有评论。
This query doesn't work
SELECT * FROM Catalogue WHERE Catalogue.ID IN (
SELECT ID_catalogue FROM Categories WHERE Categories.Product_type='xxx'
)
Error Code : 1064
You have an error in
your SQL syntax near 'SELECT
ID_catalogue FROM Categories WHERE
Categories.Product_type='xxx' ) ' at
line 2
Ok, that's because I am using a very old MySQL version.
What I am trying to get is
SELECT * FROM Catalogue WHERE Product_type='xxx' OR Catalogue.ID IN (
SELECT ID_catalogue FROM Categories WHERE Categories.Product_type='xxx'
)
Is there any equivalent for that?
Thank you for all your comments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的 mysql 版本 <= 4.0 - 那么这就是原因,因为在 4.1 中添加了子查询
您应该为表
Categories
添加复合索引ID_catalogue + Product_type
AND表Catalogue
的索引Product_type
可以快速执行此查询If you're using mysql version <= 4.0 - then it is the reason, since subqueries were added in 4.1
You should add composite index
ID_catalogue + Product_type
for tableCategories
AND indexProduct_type
for tableCatalogue
to have this query performed fast你的查询没有任何问题。您的问题很可能是 MySQL 的版本。
There is nothing wrong with your query. It is the version of MySQL that is more than likely your problem.