Reputation: 54979
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 :(
Upvotes: 1
Views: 749
Reputation: 30575
The ORDER BY
clause must be after the WHERE
clause. That's all it is.
Upvotes: 2
Reputation: 2394
$result = mysql_query("SELECT * from rests WHERE flag = '1' ORDER BY name asc LIMIT 0 , 20");
Upvotes: 5
Reputation: 455410
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
.
Upvotes: 4