Forum Moderators: coopster
I am using MySQl database and i would like to know if it's possible to order the last 5 records in a database.
In fact, i m creating a small news CMS and trying to order the last 5 articles by position_id.
select * from articles order by id DESC, position ASC limit 5
is not working. any other way to do that where i can order only the last 5 articles from the articles table.
Thanks in advance.
Dany
shouldnt this be ORBER BY position_id DESC LIMIT 5?
(instead of order by id DESC, position ASC limit 5)
I dont think you can have two diferent order types (asc, desc) in same query.
In case you definetly want both of them, heres is a solution
- create a query to get last 5 id
- use those 5 ids in a second query with different order clause
example:
from 1st query you will create a string similar to $my_string="5,10,23,67,87";
and in second query: sql=select [whatever] from [table] where id IN ($my_string) ORDER BY [something]
But i havent manage to do this in any project of mine.
So, i stick to dual queries.
Sorry i couldnt provide more info.