Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.