I have the following tables:
TableT1 TableT2
id name mid id visitdate
4 jack 1 4 2012/01/22
5 john 2 5 2012/01/21
6 mary 3 6 Null
4 5 2012/02/21
I have join this two table.. for each “id” I have to show only one record if he has multiple visit date..
Using below query I m getting record as I want
select id,name
from TableT1
left join
(
SELECT id,MAX(visitdate) AS visitdate
FROM TableT2
GROUP BY id
)as Last_Visit on TableT1.id=Last_Visit.id
order by TableT1.name,Last_Visit.visitdate Desc
My problem is to find out rownumber for each id(coloumn) and chk in condition RowNumber >=1 AND RowNumber<=3.
This should give you only the last visitdate per id and only if this id has multiple visits.