I have two tables User and UserFiles as shown below
| UserId | Name | Password | Phone | |
| 1 | First | [email protected] | 12346456 | 456456 |
| 2 | second | [email protected] | 111235 | 23235 |
User Files table Below
| RecordId(primary) | UserID(Foreign) | FileName | PublihsedBy | Date |
| 1 | 1 | First.DOc | A | 1/1/2001 |
| 2 | 1 | second.doc | B | 1/1/2012 |
| 3 | 1 | Third.Doc | B | 1/1/2016 |
| 4 | 2 | G.PDF | B | 1/1/2014 |
as you can see against one user id we have multiple files like for userid=1 we have three files I want to get the record with latest file inserted in our case i want to get the
Third.Doc how to achieve that


Shakti Singh DulawatRank #668 · 3.6K reputationPosted Jun 9, 2016, 2:58 AM EDT
Jisny AvRank #4,868 · 321 reputationPosted Aug 11, 2016, 12:02 AM EDT
(
select userid,filename,publihsedby, date,row_number()over (partition by userid order by convert(varchar(50),cast(date as datetime),102) desc) as rno
from userfiles) f
on u.userid=f.userid where f.rno=1
Ananth GRank #1,176 · 1.5K reputationPosted Oct 27, 2016, 3:13 AM EDT