Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 HOw do you count the replies in a thread?

Author  Topic 

biffysix
Starting Member

5 Posts

Posted - 2002-05-22 : 21:40:58
I am making a miniforum and I want to include the # of replies to a thread (Topic).
My Tables are

SECTION
THREADS and
MESSAGES.

I have SectionID connecting the tables SECTION and THREADS and ThreadID connecting THREADS table and the MESSAGES table.

I can show all the threads relating to a section by using SectionID as a parameter. I can get the recordset for all the messages for the thread if I can provide the ThreadID. How does it know which threadID it is before it is chosen?
I can't connect it. IT needs the ThreadID and that's the problem.

Is there a way around this? Should I make an SQL statement to join the Threads and Messages tables to find all threads for a section and the number of replies to each thread?



madhukar
Starting Member

3 Posts

Posted - 2002-05-23 : 00:35:13
try this out,
Select count(*), Threadid from messages a, Threads b where b.Sectionid = <value> and b.ThreadId = a.Threadid group by threadid

Go to Top of Page

dataphile
Yak Posting Veteran

71 Posts

Posted - 2002-05-28 : 08:16:28
or

select count(*), m.treadid
from messages m inner join threads t on t.threadid=m.threadid
where sectionid = <value>



Go to Top of Page

dataphile
Yak Posting Veteran

71 Posts

Posted - 2002-05-28 : 08:18:37
Correction

select count(*), m.treadid
from messages m inner join threads t on t.threadid=m.threadid
where sectionid = <value>
group by m.threadid

Go to Top of Page
   

- Advertisement -