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
 General SQL Server Forums
 New to SQL Server Programming
 GROUP BY ISSUE

Author  Topic 

kathyc2003
Starting Member

15 Posts

Posted - 2007-12-17 : 17:24:24

I am trying to use group by and am getting errors.
What have I done wrong

SELECT
A.ParentSubjectName,
A.ParentSubject,
A.SubjectId,
B.CreatedOn

FROM dbo.Subject A

INNER JOIN dbo.Incident B ON A.SubjectId = B.SubjectId

WHERE (B.CreatedOn >= '2007-01-01' AND B.CreatedOn <= '2007-11-30')

GROUP BY A.ParentSubjectName

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-12-17 : 17:28:21
You are missing your aggregate functions.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-12-17 : 23:08:06
[code]
SELECT
A.ParentSubjectName,
max(A.ParentSubject),
max(A.SubjectId),
max(B.CreatedOn)
FROM dbo.Subject A
INNER JOIN dbo.Incident B ON A.SubjectId = B.SubjectId
WHERE (B.CreatedOn >= '2007-01-01' AND B.CreatedOn <= '2007-11-30')
GROUP BY A.ParentSubjectName
[/code]


elsasoft.org
Go to Top of Page
   

- Advertisement -