如何从users表中选择最后3行,然后按id升序排序?
例如:
id | username | password
1 | user1 | pass1
2 | user2 | pass2
3 | user3 | pass3
4 | user4 | pass4
5 | user5 | pass5
我想选择user5,user4和user3,然后按ID ASCENDING
进行排序答案 0 :(得分:3)
使用此...
SELECT * FROM (
SELECT * FROM table ORDER BY id DESC LIMIT 3
) sub
ORDER BY id ASC