[英]Sorting private messages the newest at the bottom
I have PM system and I want to be readble from the bottom to the top, also there is LIMIT 50 to be shown 我有PM系统,我希望从下到上都可以阅读,还有LIMIT 50待显示
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. 问题是,如果我按mess_id ASC订购它会显示结果的前50个,如果还有更多则不显示。
If I order it by mess_id DESC it works but it then it shows the results at the top 如果我通过mess_id DESC对其进行排序,那么它可以正常工作,但是它将在顶部显示结果
I want the show the last 50 results and the last result to be at the bottom. 我希望显示最后50个结果,最后一个结果在底部。 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 提前致谢
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 在这里查看此答案: 从MySQL选择最后N行
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.