简体   繁体   中英

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.

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 BYWHERELIMIT之后。

WHERE之前去ORDER BY

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM