Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need

Author  Topic 

TFlorek
Starting Member

2 Posts

Posted - 2009-04-22 : 12:09:51
You may or may not be able to help me. I am using MS Access and have a table of student profiles. There are several profiles for each student and each profile has a different start date and end date - typically one per year. Each student has an ID. I need to pull data from the most recent profile - I assume the end date with the lastest date for each student - to update another table. I don't think I can do this in the query (because the dates are different for every student) - but I thought there might be a way through the SQL view. Any [simple] suggestions? Thanks.

nr
SQLTeam MVY

12543 Posts

Posted - 2009-04-22 : 12:16:50
select *
from profile p
where p.end_date = (select max(p2.end_date) frmo profile p2 where p.student_id = p2.student_id)

or

select p.*
from profile p
join (select student_id, enddate = max(enddate) from profile group by student_id) p2
on p.student_id = p2.student_id
and p.enddate = p2.enddate

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

TFlorek
Starting Member

2 Posts

Posted - 2009-04-24 : 11:29:50
Thanks so much - that was perfect!!
Go to Top of Page
   

- Advertisement -