Get latest forum topics

I want to get the latest posts from the posts table AND I want the correct topic row from another table. But I only want to get 1 latest post for every topic, and not all posts in that topic, how to do that?

[posts]
ID
topicID
name
content
timestamp

[topics]
ID
categoryID
sticky
deleted
highlighted

posts.topicID = topics.ID

So I want to get ONE latest posts per topicID where category = 4 ORDER BY timestamp DESC

thanks!

To quote Rudy: what you want is commonly called the row having the groupwise max.
Check out this thread: http://www.sitepoint.com/forums/mysql-182/collating-data-three-tables-763414.html

what you want is commonly called the row having the groupwise max

see if this thread from last week gives you a hint – http://www.sitepoint.com/forums/mysql-182/collating-data-three-tables-763414.html

ignore the fact that there were three tables involved in that one, you have only two

lol, nice replies :wink:

Any chance that’s explained inside your book which lays next to me?

Aargh, I just can’t figure it out, can you write me a query that suits my situation? There’s too much going on in that other thread

i can, but i’d rather help you do it

have a look at this other thread, also quite recent…

almost identical to your situation