2013-02-23 50 views
1

我想显示在一个表中的最后修饰元素,但结果限制为5,所以我所做的:Mysql的限制,为了通过

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个已编辑行...

我错过了什么?

回答

0

你只需要在ORDER BY子句中添加DESC以按降序排列的纪录。

ORDER BY LastModified DESC 

默认情况下,ORDER BY条款被ASCENDING顺序排序。

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 
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