tags:

views:

687

answers:

2

Master table contains ID and PersonName.
Course table contains ID, CourseName.
Detail table contains ID, MasterID, CourseID, StartDate,EndDate

I want to create report that shows list of persons (PersonName) and the only last course they took (so every person is listed only once):

PersonName - CourseName - StartDate - EndDate

+2  A: 
select m.PersonName, c.CourseName
from   Master m
join   Detail d on d.MasterID = m.ID
join   Course c on c.ID = d.CourseID
where  d.StartDate = (select max(d2.StartDate)
                      from   Detail d2
                      where  d2.MasterID = m.ID
                     )
Tony Andrews
A: 
    Select personname,coursename from details 
    inner join course on course.id = details.courseid 
    inner join master on master.id = details.masterid
    inner join (select max(startdate) ,  courseid,masterid 
    from details group by masterid,courseid ) as tb1
    on tb1.courseid = details.courseid and tb1.masterid = details.masterid
Samiksha