views:

69

answers:

1

So, i'm building a members rewarding system for my forum and got stuck on this query for selecting "forum topic with most different participants".

I already have this query that counts how many posts (replies) each forum topic in last 24 hours has.

SELECT poster . * , count( odgovori.id_odgovor ) AS broj, members.username
FROM poster
INNER JOIN odgovori ON ( odgovori.na = poster.id_poster )
INNER JOIN members ON ( poster.od = members.id_member )
WHERE poster.datum = '01.06.09'
GROUP BY odgovori.na, odgovori.od
ORDER BY broj DESC
LIMIT 1
table poster - forum topics table
table odgovori - replies table 
table members - members table, in this query only used to get topic author's username
+1  A: 
SELECT  poster.*, COUNT(DISTINCT odgovori.author) AS different
FROM    poster
JOIN    odgovori
ON      odgovori.na = poster.id_poster
GROUP BY
        poster.id
ORDER BY
        different DESC
LIMIT 1
Quassnoi
Isn't a DESC needed for the ordering?
rudolfson
@rudolfson: sure, missed it.
Quassnoi
works like charm, thanks
Kemo