I am trying to make a query that groups me by the ID_Country, Year_, Employee_ID columns and applying a max to the Employee_Name column so that it returns the employee name with more characters but for each execution it returns different results.
I am grouping to remove duplicate records the problem is that the employee name is registered in a different way
The expected result is this, so that it always returns the employee name with the largest number of characters
this is my query:
SELECT DISTINCT [ID_Country] ,[Year_] ,[Employee_ID] ,MAX([Employee_Name]) AS Employee_Name
FROM Employee_Tbl
GROUP BY [ID_Country],[Year_],[Employee_ID]
Can someone tell me the correct way to do the query and it always returns the employee name with the largest number of characters?