Select the last 3 rows from the database order by ASC ID

how can I select the last 3 rows from the users table and then sort it in ascending order?

eg:

id | username | password 1 | user1 | pass1 2 | user2 | pass2 3 | user3 | pass3 4 | user4 | pass4 5 | user5 | pass5 

I want to select user5, user4 and user3, and then order it by id ASCENDING

+4
source share
1 answer

Use this ...

 SELECT * FROM ( SELECT * FROM table ORDER BY id DESC LIMIT 3 ) sub ORDER BY id ASC 
+3
source

Source: https://habr.com/ru/post/1492557/


All Articles