Link to home
Start Free TrialLog in
Avatar of deem1
deem1

asked on

Help with TSQL Aggregate query using TOP

I have two tables, Person (id int, name varchar()) and Appointment(date datetime, personid int, notes varchar())
personid from the Appointment table reference is from the Person table.

The Person table contains is and name of some people. The Appoinment table contains the date the each person was visited. There can be many entries in the Appoinment table for each person. i.e. They is a record of many visits for each person.

I need a query that gives the 5 most recent visits for ALL the people in the Person table, not just one person. So I need a query that for each person in the person table will return the 5 (or however many) most recent vists. i.e.(date <= today).
Avatar of lausz
lausz

Can you post same sample with data and what do you want as ansewer ?
ASKER CERTIFIED SOLUTION
Avatar of RichardCorrie
RichardCorrie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial