0
    3717    8   2012-03-30 16:34:17
    3718    10  2012-03-30 16:34:22
    3719    9   2012-03-30 16:34:27
    3720    6   2012-03-30 16:34:32
    3721    7   2012-03-30 16:34:37
        3722    8   2012-03-30 16:34:42
    3723    10  2012-03-30 16:34:47
    3724    5   2012-03-30 16:34:50

i have this mysql table and iwanted to select the last 10 records i this is the code i have

SELECT * FROM mach_1 ORDER BY id DESC  LIMIT 10

this is what i get

2012-03-30 16:34:50
2012-03-30 16:34:47
2012-03-30 16:34:42
2012-03-30 16:34:37
2012-03-30 16:34:32
2012-03-30 16:34:27
2012-03-30 16:34:22
2012-03-30 16:34:17
2012-03-30 16:34:10
2012-03-30 16:34:05

the question is how can i reverse this

2
  • 2
    learn everything here: dev.mysql.com/doc/refman/5.5/en/select.html but change desc to asc Commented Mar 31, 2012 at 0:06
  • to make it simple :::: if we have a table with 1,2,3,4,5,6 if we select * from table order by id desc limit 3 we will get 6,5,4 how do i reverse the result Commented Mar 31, 2012 at 0:12

2 Answers 2

3

Try something like this:

select * from (select * from mach_1 order by id desc 
limit 10) as tbl order by tbl.id;
Sign up to request clarification or add additional context in comments.

Comments

1

Most likely you won't get around a nested select:

SELECT * FROM (SELECT * FROM mach_1 ORDER BY id DESC LIMIT 10) AS t ORDER BY t.id ASC

This will first select the last 10 entries and afterwards sort them ascending like you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.