• Welcome! Please take a look at the article in my signature about posting questions to the forums. Table definitions and sample data is always useful. What I would recommend iswith cte as

    (SELECT ROW_NUMBER() over (partition by dbo.HemAnimal.AniUserNumber order by dbo.PrmDeviceVisit.DviEndTime DESC) as rowNum, dbo.HemAnimal.AniUserNumber, dbo.HemAnimal.AniResponderNumber, dbo.PrmDeviceVisit.DviStartTime, dbo.PrmDeviceVisit.DviEndTime,

    dbo.PrmDeviceVisit.DviMilkVisit, dbo.PrmDeviceVisit.DviFailure, dbo.PrmMilkVisit.MviLFTeatWidth, dbo.PrmMilkVisit.MviLRTeatWidth,

    dbo.PrmMilkVisit.MviRFTeatWidth, dbo.PrmMilkVisit.MviRRTeatWidth

    FROM dbo.HemAnimal INNER JOIN

    dbo.PrmDeviceVisit ON dbo.HemAnimal.AniId = dbo.PrmDeviceVisit.DviAniId INNER JOIN

    dbo.PrmMilkVisit ON dbo.PrmDeviceVisit.DviId = dbo.PrmMilkVisit.MviDviId

    )

    select *

    from CTE

    where rowNum <= 3

    This should give you what you want.



    Microsoft Certified Master - SQL Server 2008
    Follow me on twitter: @keith_tate

    Forum Etiquette: How to post data/code on a forum to get the best help[/url]