Question : Select All Columns Count Column Group By Only One Column?

I would like to do this, but sql requires using all columns in the 'Group By'. Doing so messes-up my group-by and CodeCnt return. Help...

Select ID, NameLast, NameFirst, Dept, Code, count(Code) As CodeCnt, Convert(varchar,Convert(datetime, Occurance),22) As Occ
From Employees
Where NameLast In ('Jones')
And NameFirst In ('Bob')
Group By Code
Order By CodeCnt

Answer : Select All Columns Count Column Group By Only One Column?

Try this.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
SELECT
	A.ID
	,A.NameLast
	,A.NameFirst
	,A.Dept
	,A.Code
	,B.CodeCnt
	,Convert(varchar,Convert(datetime, Occurance),22) As Occ 
FROM 
	Employees A
	INNER JOIN (SELECT Code,COUNT(Code) CodeCnt FROM Employees GROUP BY Code) B
		ON A.Code = B.Code
WHERE
 	A.NameLast In ('Jones') 
	And A.NameFirst In ('Bob') 
Order By B.CodeCnt
Random Solutions  
 
programming4us programming4us