PDA

View Full Version : Pulling a specific number of threads from each forum.. can it be done in one query?


djnoz
04-15-2004, 11:43 PM
What I need to do, is write a query that pulls the latest 4 threadids out of a specified list of forumids individually.

So basically, if I was specifying forumids 1 and 2, the query would display two lists of the four latest threadids from those forums.

The output at the mysql console would look something like this


Forumid |Threadid
1 |12
1 |11
1 |9
1 |7

2 |13
2 |10
2 |8
2 |6


Is this possible, or must I run multiple queries?

Thanks :)

Velocd
04-17-2004, 04:30 AM
SELECT *
FROM thread
WHERE forumid IN ($forumid_list)
ORDER BY dateline
LIMIT 4

This is what you need, if I understood you correctly.

djnoz
04-17-2004, 05:56 AM
The problem with that query is that I want the 4 latest threads from each forum... that query takes the 4 latest threads aggregated together from both forums.

If two forums are specified, the query should return 8 values - 4 threads from the first forum, and 4 threads from the second forum. I haven't been able to figure out how to do this without running a seperate query for each forum.

Thanks for the reply anyway. ;)