![](/img/trans.png)
[英]Simple SQL query not using index with order clause and larger limit MariaDB
[英]syntax error in sql query while using ORDER and LIMIT clause?
使用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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.