Mysql限制和排序依据

时间:2013-02-23 17:18:05

标签: mysql sql-order-by limit

我想在表格中显示最后修改的元素,但将结果限制为5,所以我做了:

SELECT
  Id as Id,Title,LastModified
From
  articles
WHERE
  (Author=70 OR Editor=32 OR Publisher=33) && Disab ="0"

Order By   LastModified

LIMIT 0, 5

此查询的问题是它返回表的前5行,而不是最后5行编辑的行......

我缺少什么?!

3 个答案:

答案 0 :(得分:1)

默认ORDER BY是升序。你想下降

SELECT
  Id as Id,Title,LastModified
From
  articles
WHERE
  (Author=70 OR Editor=32 OR Publisher=33) && Disab ="0"

Order By   LastModified DESC

LIMIT 0, 5

答案 1 :(得分:0)

试试这个

SELECT
  Id as Id,Title,LastModified
From
  articles
WHERE
  (Author=70 OR Editor=32 OR Publisher=33) && Disab ="0"

Order By   LastModified DESC

LIMIT 0, 5

答案 2 :(得分:0)

您只需在DESC子句中添加ORDER BY即可按降序对记录进行排序。

ORDER BY LastModified DESC

默认情况下,ORDER BY子句按ASCENDING顺序排序。