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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Obtain last time you get a course

Author  Topic 

shifis
Posting Yak Master

157 Posts

Posted - 2006-03-24 : 18:04:07
I have table that have information of the Course that a person took, it have the next fields:

Company
IDEmployee
CourseNumber
Grade
Date

One person can take the same course more that ones, how can I do a query that only gave me the list and calification per Employee of the last course the he took.

For example

Employee:40887

company courseNumber Grade Date
2000 257 100.00 2006/01/24
2000 257 92.50 2006/02/05
2000 257 98.00 2006/03/21
2000 175 100.00 2006/02/05
2000 147 89.00 2006/01/01
2000 147 87.00 2006/01/12

The query must return

2000 257 98.00 2006/03/21
2000 175 100.00 2006/02/05
2000 147 87.00 2006/01/12


(I hope you undestand my English)


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-24 : 19:53:22
[code]select *
from yourtable t
where IDEmployee = 40887
and Date = (select max(Date) from yourtable x where x.IDEmployee = t.IDEmployee and x.CourseNumber = t.CourseNumber)[/code]



KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page
   

- Advertisement -