-2

谁能帮我弄清楚为什么我在这个查询中得到一个 SQL 错误:

SELECT * FROM articles 
       LIMIT $offset, $rowsperpage 
       ORDER BY article_timestamp DESC

非常感谢!

4

3 回答 3

1

LIMIT子句放在查询的末尾。

SELECT * FROM articles
ORDER BY article_timestamp DESC
LIMIT $offset, $rowsperpage


您必须遵循MySQL 的语法..

SELECT
    [ALL | DISTINCT | DISTINCTROW ]
      [HIGH_PRIORITY]
      [STRAIGHT_JOIN]
      [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
      [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr [, select_expr ...]
    [FROM table_references
    [WHERE where_condition]
    [GROUP BY {col_name | expr | position}
      [ASC | DESC], ... [WITH ROLLUP]]
    [HAVING where_condition]
    [ORDER BY {col_name | expr | position}
      [ASC | DESC], ...]
    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
    [PROCEDURE procedure_name(argument_list)]
    [INTO OUTFILE 'file_name' export_options
      | INTO DUMPFILE 'file_name'
      | INTO var_name [, var_name]]
    [FOR UPDATE | LOCK IN SHARE MODE]]

更多信息:- MySQL SELECT 手册

于 2013-10-09T13:15:22.350 回答
1

限制应该结束。它应该先订购然后获得有限的行

SELECT * FROM articles 
ORDER BY article_timestamp DESC
LIMIT $offset, $rowsperpage
于 2013-10-09T13:16:01.233 回答
0

试试这个:

SELECT * 
FROM   ARTICLES 
ORDER  BY ARTICLE_TIMESTAMP DESC 
LIMIT  $OFFSET, $ROWSPERPAGE
于 2013-10-09T13:14:44.077 回答