If forum_post primary key automatically increases (it should be, but we never know ...), this will return you what you need:
SELECT c.forum_cat_id, COUNT(p.fk_forum_cat_id), MAX(p.date_added), (SELECT p2.post_title FROM forum_post AS p2 WHERE p2.forum_post_id = (SELECT MAX(p3.forum_post_id) FROM forum_post AS p3 WHERE p3.fk_forum_cat_id = p2.fk_forum_cat_id) AND p2.fk_forum_cat_id = c.forum_cat_id) FROM forum_cat AS c INNER JOIN forum_post AS p ON p.fk_forum_cat_id = c.forum_cat_id GROUP BY c.forum_cat_id;
I had to guess the field names:
forum_cat_id = forum _cat primary keyforum_post_id = forum_post primary keypost_title = post name or the beginning of the text message in forum_post (depends on what you want to show).- The
COUNT(p.fk_forum_cat_id) column COUNT(p.fk_forum_cat_id) will indicate the number of posts in the category
In addition to what you requested, you will get the date of the last post in the category, as I think you will need it if this is a good forum;).
Obs: I have not tested it, so you may need debugging. If you have problems, let me know.
source share