I am using the following SQL code, where the Id
and DateTime
columns are the same and I want to group them together. The Ref
is different and in this example I have 3 names with the same Id
and DateTime
. I want to get one row of data output like this:
Id DateTime Ref
---------------------------------------------
3 Sep 4 2021 08:00:00 Billy Joel
Chris Farley
Joe Blow
Instead I'm getting 3 rows of data:
Id DateTime Ref
---------------------------------------------
3 Sep 4 2021 08:00:00 Billy Joel
3 Sep 4 2021 08:00:00 Chris Farley
3 Sep 4 2021 08:00:00 Joe Blow
Below is a my SQL code and sqltest site with my data and SQL query. Can anyone help?
Select
a.Id, a.DateTime,
(o.cFName + ' ' + o.cLName) as Ref
From
GameAssignment g
Left Outer Join
games a on g.gameId = a.Id
Left Outer Join
FieldGym f On a.FieldGym = f.Id
Left Outer Join
Official o On o.Id = g.OfficialId
Where
Convert(date, a.DateTime) = '09/04/2021'
And f.Id = 3
Group by
a.Id, o.cFName, o.cLName, a.DateTime
Order by
a.DateTime
SQL test site https://sqltest.net/#1422359