我有以下声明
$result = mysql_query("SELECT * from rests ORDER BY name asc WHERE flag = '1' LIMIT 0 , 20");
我收到以下错误
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
我不确定哪里出错了:(
答案 0 :(得分:5)
$result = mysql_query("SELECT * from rests WHERE flag = '1' ORDER BY name asc LIMIT 0 , 20");
答案 1 :(得分:4)
ORDER BY
子句之前不能有WHERE
子句。
请参阅MySQL select syntax了解各种条款的正确顺序。
试试这个:
SELECT * from rests WHERE flag = '1' ORDER BY name asc LIMIT 0 , 20
另外,以升序排序是默认的,您可以放弃asc
。
答案 2 :(得分:2)
ORDER BY
子句必须在WHERE
子句之后。就是这样。
答案 3 :(得分:2)
ORDER BY
位于WHERE
和LIMIT
之后。
答案 4 :(得分:1)
WHERE
早于ORDER BY
。