I have a problem with group by, I want to select multiple columns but group by only one column. The query below is what I tried, but it gave me an error.
SELECT Rls.RoleName,Pro.[FirstName],Pro.[LastName],Count(UR.[RoleId]) as [Count]
from [b.website-sitecore-core].[dbo].[aspnet_UsersInRoles] UR
inner join [b.website-professional-au].[dbo].[Profile] Pro
on UR.UserId = Pro.Id
inner join [b.website-sitecore-core].[dbo].[aspnet_Roles] Rls
on Rls.RoleId = UR.RoleId
inner join [b.website-professional-au].[dbo].[Gender] Gn
on gn.Id = pro.GenderId
GROUP BY Rls.RoleName;
GROUP BY A,B,Ccan be totally different than what you want to get in comparison withGROUP BY A. and also, usually we can't use some aggregate function to get related column value. check this answer as a solution – S.Serpooshan Dec 25 '18 at 11:00