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.
| Author |
Topic |
|
Petehe
Starting Member
20 Posts |
Posted - 2004-04-27 : 03:54:19
|
| I have a table likeCustomerID, EmployeeID, EmployStartDate1, 1, 1/1/20031, 2, 1/4/20042, 3, 1/1/20032, 4, 1/5/2005Could u design a query to show which one is most recent employed for each company?Thanks |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-04-27 : 04:00:12
|
| SELECT TOP 1 WITH TIES CustomerID, EmployeeID, EmployStartDateFROM TableNameORDER BY EmployStartDate DESC--**** WITH Ties brings back more than 1 if the latest employstartdates are equalDuane. |
 |
|
|
Petehe
Starting Member
20 Posts |
Posted - 2004-04-27 : 22:43:53
|
| Thanks for your help.But I want something will show me the most recent employee of each company?Something like 1, 2, 1/4/20042, 4, 1/5/2005 |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-04-27 : 23:02:27
|
| SELECT e1.CustomerID, e1.EmployeeID, e1.EmployeeStartDateFROM Employee e1 INNER JOIN ( SELECT CustomerID, MAX(EmployeeStartDate) AS EmployeeStartDate FROM Employee) e2 ON e1.CustomerID = e2.CustomerID AND e1.EmployeeStartDate = e2.EmployeeStartDateMeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
Petehe
Starting Member
20 Posts |
Posted - 2004-04-27 : 23:20:48
|
| Thank you so much, that's what I want. |
 |
|
|
|
|
|
|
|