How to get the latest row from table using JOIN

thanhp

New Member
I have a join of 5 tables to get the tasks posted by each member having about 15 columns. But for sample code I have taken just two tables of them. \[code\]SELECT TOP 5 dbo.MemberMst.MemberID, dbo.MemberMst.fname, dbo.TaskMst.TaskMstID, dbo.TaskMst.OnDate, dbo.TaskMst.DescriptionFROM dbo.MemberMst LEFT JOIN dbo.TaskMst ON dbo.MemberMst.MemberID = dbo.TaskMst.MemberID\[/code\]Output is:\[code\]MemberID fname TaskMstID OnDate Description3 Ursula NULL NULL NULL84 Opeyemi 30 2012-09-18 00:00:00.000 asd85 test 21 2012-09-18 10:30:46.900 aaa85 test 22 2012-09-18 10:31:04.967 eeee85 test 23 2012-09-18 10:31:26.640 vvvv\[/code\]Here in above query I get 3 rows for \[code\]MemberID=85\[/code\] who posted 3 tasks but I need only one task from that member which is the latest. How to get the latest task posted by a member so that result would be:-\[code\]MemberID fname TaskMstID OnDate Description3 Ursula NULL NULL NULL84 Opeyemi 30 2012-09-18 00:00:00.000 asd85 test 23 2012-09-18 10:31:26.640 vvvv\[/code\]I mean to say just only one record for each \[code\]memberID\[/code\] having tasks?Help appreciated..!Thanks in advance...!
 
Back
Top