This is my table structure
MyTable
ID[P.K][auto increment] TopicID UID Comment
Now i want to get the last 20 comment for a TopicID but it should be sorted in ascending order !
[Just like Facebook by default shows last 20 comment only]
I am looking for an optimized version, i can do this with 2/3 query and php sort array, but looking for some better alternative
Sample Result with data
MyTable
ID TopicID UID Comment
1 1 10 AAAA
2 1 11 BBBB
3 1 10 CCCC
4 1 10 dddd
5 1 11 EEEE
6 1 10 FFFF
I want to get the last 3 result for a TopicID, the result should be
4 1 10 dddd
5 1 11 EEEE
6 1 10 FFFF
and not
6 1 10 FFFF
5 1 11 EEEE
4 1 10 dddd
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…