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 2008 Forums
 Transact-SQL (2008)
 count with join not working. please help

Author  Topic 

mary_itohan
Posting Yak Master

191 Posts

Posted - 2012-03-08 : 04:22:27
hi guys,
I have two tables, with the subcatID as PK and FK. And want to get the count of the subcat in the foreign table and also list subcat names.

Here is my code


SELECT dbo.sub_categories.name, COUNT(dbo.Training_courses.subcategoryID) AS Expr1, dbo.Training_courses.subcategoryID
FROM dbo.sub_categories INNER JOIN
dbo.Training_courses ON dbo.sub_categories.subcategoryID = dbo.Training_courses.subcategoryID
GROUP BY dbo.sub_categories.name, dbo.Training_courses.Coursename, dbo.Training_courses.subcategoryID


_____________________


Yes O !

sqllearner05
Starting Member

9 Posts

Posted - 2012-03-08 : 07:56:21
Remove dbo.Training_courses.Coursename column from group by clause, then it gives expected result

sqllearner
Go to Top of Page

mary_itohan
Posting Yak Master

191 Posts

Posted - 2012-03-08 : 08:08:52
ok thanks it worked.

_____________________


Yes O !
Go to Top of Page
   

- Advertisement -