Hi Richa,
Refer below query which full fill your requirement
SQL
DECLARE @Table AS TABLE(Id INT,Project_Id VARCHAR(6),Rev_Id VARCHAR(30),[Date] DATETIME,[Version] VARCHAR(40))
INSERT INTO @Table VALUES(1,'P12','ABC1001','2-Aug-2016','V12.0.10')
INSERT INTO @Table VALUES(1,'P12','ABC1002','12-April-2016','V12.0.10')
INSERT INTO @Table VALUES(1,'P12','ABC1003','12-April-2016','V12.0.10')
INSERT INTO @Table VALUES(2,'P15','ABC1004','1-July-2016','V12.0.3')
INSERT INTO @Table VALUES(3,'P19','ABC1005','8-Aug-2016','V12.0.4')
INSERT INTO @Table VALUES(3,'P19','ABC1006','13-July-2016','V12.0.4')
SELECT Id,Project_Id,Rev_Id,[Date],[Version]
FROM
(
SELECT ROW_NUMBER() OVER(PARTITION BY(Project_Id) ORDER BY [Date] DESC)RowNo,*
FROM @Table
) t
WHERE t.RowNo = 1
Output
Id |
Project_Id |
Rev_Id |
Date |
Version |
1 |
P12 |
ABC1001 |
2-Aug-16 |
V12.0.10 |
2 |
P15 |
ABC1004 |
1-Jul-16 |
V12.0.3 |
3 |
P19 |
ABC1005 |
8-Aug-16 |
V12.0.4 |
I Hope this works for you