Reputation:
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
Upvotes: 0
Views: 85
Reputation: 2188
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.
Upvotes: 1
Reputation: 741
Try something like this:
select * from (select * from mach_1 order by id desc
limit 10) as tbl order by tbl.id;
Upvotes: 3