使用 ORDER 和 LIMIT 时存在语法错误。我对mysql不熟悉,能否指出错误。
ps = con.prepareStatement("Select product_id,image_name,images.product_name,price,"
+ "company_name from images,products"
+ "where images.product_name = products.product_name ORDER BY hits DESC LIMIT 5");
最佳答案
问题是在连接字符串时 products
和 where
之间没有空格,所以查询最终看起来像
... from images,productswhere images.product_name = ...
在其中一个字符串中添加一个空格:
ps = con.prepareStatement("Select product_id,image_name,images.product_name,price,"
+ "company_name from images,products"
+ " where images.product_name = products.product_name ORDER BY hits DESC LIMIT 5");
您没有说明您使用的是哪种编程语言,但许多语言允许字符串跨行,因此您不需要串联。然后你可以写:
ps = con.prepareStatement("Select product_id,image_name,images.product_name,price,company_name
from images,products
where images.product_name = products.product_name
ORDER BY hits DESC LIMIT 5");
关于mysql - 使用 ORDER 和 LIMIT 子句时 sql 查询中的语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42865292/