Jump to content

Need help with a very tricky mysql query (one table)


turkman

Recommended Posts

ok have a table.  like the following.

 

ID // title // ReplyToo // message

 

ok, so its for a forum... the above are the only rows we need.

ID is each posts unique identifyer.

title is the tile of the topic. It will only have a title if its a new thread otherwise it has the value of blah

ReplyToo is for replys to topic, it will equal the ID of the topic its replying too, if its a new topic its value will be 0 Message is the message of the topic

 

So we might have the following

 

ID//////title//////ReplyToo//////message

1 //////Hi there/  0    /////////// This is a new thread

2 //////blah /////  1  //////////// im replying to a new thread

 

ID 1 is starting a new thread of title Hi there, notice its replytoo value is 0

ID 2 is replying to ID1 thread and because it doesn't have a title its set to blah ReplyToo is 1 because its replying to ID1

 

Ok now i have explained..Here is what i want.

 

I want a query that will count the replys to each thread then order them by most replies.

 

This means the query must find all threads with a ReplyToo value of  0 Get its ID, find and count all threads with a ReplyToo value of ID  Then return them in order

 

Thread title // num of replies.

Link to comment
Share on other sites

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.