Say I have a table of topics in a forum, with the following parameters as follows: (obviously there's more but these are the only important ones)
last_update_date: last time it was updated
id_last_msg: The last post that is in this topic
id_board: The forum that it's in.
I want to make a query that will return a list of the last topic of each forum I specify in a IN function. Take this query for example:
But what I want to actually do is make it so the rows returned are the last topic in that forum, so where last_update_date is the largest but only for that particular forum. I was trying to figure out a way using the max function but no go.
How do I do this in a single query? It would be easier to do it in separate queries and just use ORDER BY and LIMIT 1 but that would require revamping pretty much the whole code of what I'm changing.
last_update_date: last time it was updated
id_last_msg: The last post that is in this topic
id_board: The forum that it's in.
I want to make a query that will return a list of the last topic of each forum I specify in a IN function. Take this query for example:
Code:
SELECT id_board, id_last_msg FROM smf_topics WHERE id_board IN (1,23) group by id_board
But what I want to actually do is make it so the rows returned are the last topic in that forum, so where last_update_date is the largest but only for that particular forum. I was trying to figure out a way using the max function but no go.
How do I do this in a single query? It would be easier to do it in separate queries and just use ORDER BY and LIMIT 1 but that would require revamping pretty much the whole code of what I'm changing.
