[英]MySQL Where Clause error
i have the following statement 我有以下声明
$result = mysql_query("SELECT * from rests ORDER BY name asc WHERE flag = '1' LIMIT 0 , 20");
am getting the following error 正在收到以下错误
Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE flag = '1' LIMIT 0 , 20' at line 1
am not sure where am going wrong :( 不知道哪里出了问题:(
$result = mysql_query("SELECT * from rests WHERE flag = '1' ORDER BY name asc LIMIT 0 , 20");
You cannot have the ORDER BY
clause before WHERE
clause. 您不能在WHERE
子句之前有ORDER BY
子句。
Refer to the MySQL select syntax for the correct order of various clauses. 有关各种子句的正确顺序,请参考MySQL select语法 。
Try this: 尝试这个:
SELECT * from rests WHERE flag = '1' ORDER BY name asc LIMIT 0 , 20
Also Ordering in ascending is default, you may drop the asc
. 同样,默认asc
,您可以删除asc
。
The ORDER BY
clause must be after the WHERE
clause. ORDER BY
子句必须在WHERE
子句之后。 That's all it is. 仅此而已。
ORDER BY
在WHERE
和LIMIT
之后。
WHERE
之前去ORDER BY
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.