I want to get last five records from the table using LIMIT in MySQL but also I am in need to get those records in ascending order. I do the following:
SELECT emp_id, emp_name FROM employ ORDER BY emp_id DESC LIMIT 5;
Obviously, the result will be like below:
emp_id emp_name
10 name10
9 name9
8 name8
7 name7
6 name6
Actually, I want the results in ascending order like below:
emp_id emp_name
6 name6
7 name7
8 name8
9 name9
10 name10
Is there any solution to get the results in ascending order?
To get last top records using LIMIT in MySQL also in ascending order is possible. You may amend your above query as below. The trick will serve your purpose:
(SELECT emp_id, emp_name FROM employ ORDER BY employ_id DESC LIMIT 5)
ORDER BY emp_id ASC;