Reputation: 83
I have PM system and I want to be readble from the bottom to the top, also there is LIMIT 50 to be shown
The problem is if i order it by mess_id ASC it shows the first 50 resultd and if there are more they don't show.
If I order it by mess_id DESC it works but it then it shows the results at the top
I want the show the last 50 results and the last result to be at the bottom. In the table there is also date field. This is one of the codes
SELECT mess_id, message, mess_from_id, date FROM messages ORDER BY mess_date DESC LIMIT 50
I'll be grateful if someone can help
Thanks in advance
Upvotes: 0
Views: 206
Reputation: 1270401
You need a "double order by":
select m.*
from (SELECT mess_id, message, mess_from_id, date
FROM messages
ORDER BY mess_date DESC
LIMIT 50
) m
order by mess_date ASC;
Upvotes: 0
Reputation: 1154
SELECT * FROM (
SELECT * FROM table ORDER BY id DESC LIMIT 50
) sub
ORDER BY id ASC
See this answer here: Select last N rows from MySQL
Upvotes: 4