Reputation: 71
I have this table:
postID | postTitle | date
1 | example1 | 04/06/2014 ***15:00***
2 | example2 | 04/06/2014 ***14:00***
3 | example3 | 04/06/2014 ***14:20***
3 | example4 | 04/06/2014 ***10:00***
3 | example5 | 04/06/2014 ***09:00***
Current time: 16:00
How can I do three queries where for example query 1 selects the most recent row, query 2 selects the second most recent row and query 3 selects the third most recent row?
Upvotes: 0
Views: 67
Reputation: 60493
Just use an order desc, and limit
select *
from yourTable
order by `date` desc
limit 3
Limit with 1 argument : argument = number of rows.
Limit with 2 argument : first = offset, second = number (offset starting at 0, not 1)
first row
limit 1 -- or limit 0, 1
second row
limit 1, 1
third row
limit 2, 1
Upvotes: 1