开发者

MySQL Where Clause error

开发者 https://www.devze.com 2023-01-29 09:08 出处:网络
i have the following statement $result = mysql_query(\"SELECT * from rests ORDER BY name asc WHERE flag = \'1\' LIMIT 0 , 20\");

i have the following statement

$result = mysql_query("SELECT * from rests ORDER BY name asc WHERE flag = '1' LIMIT 0 , 20");

am开发者_JAVA技巧 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.

Refer to the MySQL select syntax for the correct order of various clauses.

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.


The ORDER BY clause must be after the WHERE clause. That's all it is.


ORDER BY comes after the WHERE and LIMIT at the end.


WHERE goes before ORDER BY.

0

精彩评论

暂无评论...
验证码 换一张
取 消