Jump to content

I need help with a sql command... to count and then order by that count


turkman

Recommended Posts

Hey im creating a forum and i want to list the most popular topics on the page, i was going to sort it by replies however i have a problem... in my table there is no running total of replies, there is only a new entry for each reply - so if i want to get the total replies for a thread id do select * from table_name where id = 'id'  then id do a mysql_num_rows() and get the replies

 

however when i want to show the number of replies and sort them by the most replied this becomes a problem... is there a way of doing this in sql?

thanks.. thats gave me a basic overview... one difference though my topics and replies are in the same table... i just have a replytoo column 0 = new thread - anything over 0 is the thread id its replying too.

 

would that be

 

SELECT table_name.id, COUNT(table_name.replytoo) as totreply
FROM table_name
WHERE table_name.replytoo > 0
GROUP BY table_name.id
ORDER BY totreply DESC

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.