Hi gokuldas,
Please refer below query.
SQL
DECLARE @TestDemo AS TABLE (Id INT, RegNo INT, Name VARCHAR(20), Place VARCHAR(20), Address VARCHAR(20), Gender VARCHAR(10),Age INT,Phone VARCHAR(50), Mob VARCHAR(50), Email VARCHAR(50), Doctor VARCHAR(20), Date DATETIME, Remark VARCHAR(10))
INSERT INTO @TestDemo VALUES(1,1, 'Ramesh' ,'Kakkanad' ,'Ernakulam', 'Male' ,36 ,'04902323098' ,'9879068679' ,'arun.k@gmail.com' ,'Arun','2018-09-19 00:00:00.000' ,'')
INSERT INTO @TestDemo VALUES(2,2 , 'sumesh' , 'Kannur' , 'kannur' , 'Male' , 36 ,'9758956560','9746028240' , 'sumesh.k@gmail.com' ,'Arun,' ,' 2018-09-19 00:00:00.000','' )
INSERT INTO @TestDemo VALUES(3,3 , 'Anil' ,'Mumbai','kannur' ,'Male',30 , '9878989890','9789089890' ,'anil.k@gmail.com' ,'Arun,' ,'2018-09-19 00:00:00.000','' )
INSERT INTO @TestDemo VALUES(4,4, 'Manoj' ,'mumbai','' ,'Male', 25 ,'9878989890', '', '', ' Arun', '2018-09-19 00:00:00.000','')
INSERT INTO @TestDemo VALUES(4 ,4 ,'Manoj' ,'mumbai','' ,'Male', 25 ,'9878989890', '', '', 'Prashanth ','2018-09-20 00:00:00.000','')
SELECT Id,RegNo,Name,Place,Address,Gender, Age, Phone, Mob, Email,Doctor,Date FROM
(SELECT ROW_NUMBER() OVER(PARTITION BY RegNo ORDER BY(Date) DESC) row, * FROM @TestDemo) Demo
WHERE row = 1
Screenshot
Id |
RegNo |
Name |
Place |
Address |
Gender |
Age |
Phone |
Mob |
Email |
Doctor |
Date |
1 |
1 |
Ramesh |
Kakkanad |
Ernakulam |
Male |
36 |
4.9E+09 |
9.88E+09 |
arun.k@gmail.com |
Arun |
00:00.0 |
2 |
2 |
sumesh |
Kannur |
kannur |
Male |
36 |
9.76E+09 |
9.75E+09 |
sumesh.k@gmail.com |
Arun, |
00:00.0 |
3 |
3 |
Anil |
Mumbai |
kannur |
Male |
30 |
9.88E+09 |
9.79E+09 |
anil.k@gmail.com |
Arun, |
00:00.0 |
4 |
4 |
Manoj |
mumbai |
|
Male |
25 |
9.88E+09 |
|
|
Prashanth |
00:00.0 |