Forum section table:
Forum post table:
Rendering:
为情所困2017-06-29 10:10:50
If one SQL statement cannot do this, it is recommended to loop through all sections and use SELECT ... WHERE fid = ? ORDER BY dateline LIMIT 6
to get the latest 6 posts. To improve efficiency, (fid, dateline)
Can be made into a composite index.
In addition, it is possible to use a SQL statement to find out the latest 1 posts in each forum, but it is not easy. Give it a try :-)
学习ing2017-06-29 10:10:50
If there are many sections, union is more troublesome. The following SQL can get the result
If your tid and dateline are in the same order, you can write like this:
1 2 3 4 5 6 7 8 |
|
If the order is inconsistent, use the following:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
···························Separating line··················· ···············
In addition, you can also introduce the line number within the group, which seems to be easier:
1 2 3 4 5 6 7 8 9 10 11 12 |
|