I am trying to get the list of employees and their nationalities :
select concat([Firstname],[Lastname]) as \'Full name\',[C].[Label] as \'Nationality\' FROM [
Use ROW_NUMBER
:
WITH cte AS (
SELECT CONCAT([Firstname], [Lastname]) AS full_name,
[C].[Label] AS Nationality,
ROW_NUMBER() OVER (PARTITION BY E.EmployeeId ORDER BY UpdateDate DESC) rn
FROM [Employee] [E]
LEFT JOIN [AF_AdminFile] [AFA]
ON E.AdminFileId = AFA.AdminFileId
LEFT JOIN [AF_Nationality] [AFN]
ON AFN.AdminFileId = AFA.AdminFileId
LEFT JOIN [Country] [C]
ON AFN.CountryId = C.ID
)
SELECT
full_name,
Nationality
FROM cte
WHERE rn = 1;