16,003,277 members
See more:
`Get all the employees latest Document date in sql server `

```No	Employee	DocumentDateNew
1	Employee1	3/22/2018
2	Employee1	5/22/2018
3	Employee1	10/23/2017
4	Employee2	3/21/2018
5	Employee2	6/22/2018
6	Employee2	10/23/2017
7	Employee2	10/12/2017
8	Employee3	3/22/2018
9	Employee3	11/10/2017```

i need result like
```NO	Employee	DocumentDateNew
1	Employee1	3/22/2018
4	Employee2	3/21/2018
8	Employee3	3/22/2018```

What I have tried:

Get the record all the employee based on latest documents date
Posted
Updated 23-Mar-18 7:26am
v3

## Solution 1

SQL
`SELECT EMPLOYEE,MAX(DOCUMENTDATE) FROM EMPLOYEETABLE GROUP BY EMPLOYEE`

DhananjayanP 23-Mar-18 1:33am
thank you for your answer, but I am getting EMPLOYEE name as Duplicate

## Solution 2

select Employee, max(DocumentDateNew) as DocumentDateNew from emptable group by Employee

DhananjayanP 23-Mar-18 2:01am
thank you for your answer, but I am getting EMPLOYEE name as Duplicate
itsmypassion 23-Mar-18 2:28am
Do not include Column "No" in Group by List.

## Solution 3

If you need to include the "No" column:
SQL
```WITH cte As
(
SELECT
No,
Employee,
DocumentDateNew,
ROW_NUMBER() OVER (PARTITION BY Employee ORDER BY DocumentDateNew DESC) As RN
FROM
YourTable
)
SELECT
No,
Employee,
DocumentDateNew
FROM
cte
WHERE
RN = 1
;```

Demo[^]
ROW_NUMBER (Transact-SQL) | Microsoft Docs[^]

NB: Your expected output is wrong. Taking Employee1 as an example, 22nd May 2018 is later than 22nd March 2018, so the output should return row 2, not row 1.