I have the following code that I want to return the room assignment and occupants of that room.
These are the results I get:
[tt]
Assignment FN1 LN1 FN2 LN2
CDV B206 Johnson Jasmine Rossouw Aileen
CDV B206 Rossouw Aileen Johnson Jasmine
CDV B207 Hailey STANLEY Roberson Reginald
CDV B207 Roberson Reginald Hailey STANLEY
CDV B208 Brown Tamaneka Cammack LAUREN
CDV B208 Cammack LAUREN Brown Tamaneka
[/tt]
What I want is for it to return only one row per Assignment.
Code:
SELECT TOP 100 PERCENT A.Assignment, A.FirstName AS FN1, A.LastName AS LN1, B.FirstName AS FN2, B.LastName AS LN2
FROM dbo.housemail A LEFT OUTER JOIN
dbo.housemail B ON A.Assignment = B.Assignment AND A.FirstName + A.LastName <> B.FirstName + B.LastName
GROUP BY A.Assignment, A.FirstName, B.FirstName, B.LastName, A.LastName
ORDER BY A.Assignment
These are the results I get:
[tt]
Assignment FN1 LN1 FN2 LN2
CDV B206 Johnson Jasmine Rossouw Aileen
CDV B206 Rossouw Aileen Johnson Jasmine
CDV B207 Hailey STANLEY Roberson Reginald
CDV B207 Roberson Reginald Hailey STANLEY
CDV B208 Brown Tamaneka Cammack LAUREN
CDV B208 Cammack LAUREN Brown Tamaneka
[/tt]
What I want is for it to return only one row per Assignment.