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
 SQL Server Development (2000)
 counting total no of records in child table

Author  Topic 

Swati Jain
Posting Yak Master

139 Posts

Posted - 2006-09-29 : 09:08:02

I have 2 tables
parent table
is tlbForum with fields 'questioID'(primary key),'author'
child table
is tlbAnswer with field questionID(Foreign key),answerID(pk),name

from that i want to select total answers submitted and other fields
in the parent table (tlbForum)

i tried as follows select count(tlbanswer.answerID),tlbforum.author
group by tlbanswer.fquestionID
where tlbForum.questionID=tlbanswer.questionID
but it is not working
How to make it correct?
Swati Jain

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-29 : 09:12:25
Select F.QuestionId,count(C.answers) from tblChild C inner join tblForum F
on C.questionId=F.questionId

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-29 : 09:17:28
GROUP BY must be written after WHERE.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-29 : 09:24:21
Also, your SELECT list can contain only those fields which are in GROUP BY or aggregations like count(), Sum() etc. In your case, you are grouping on fQuestionID but including author column in the SELECT list.

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-29 : 09:33:56
Swati, Learn SQL

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -