How can I select values from different rows depending on the most recent entry date, all for the sam

Posted by user321185 on Stack Overflow See other posts from Stack Overflow or by user321185
Published on 2010-04-20T10:41:42Z Indexed on 2010/04/21 7:03 UTC
Read the original article Hit count: 463

Filed under:
|
|
|
|

Basically I have a table which is used to hold employee work wear details. It is formed of the columns:

EmployeeID, CostCentre, AssociateLevel, IssueDate, TrouserSize, TrouserLength, TopSize & ShoeSize. 

An employee can be assigned a pair of trousers, a top and shoes at the same time or only one or two pieces of clothing. As we all know peoples sizes and employee levels can change which is why I need help really. Different types of employees (associatelevels) require different colours of clothing but you can ignore this part. Everytime an employee receives an item of clothing a new row will be inserted into the table with an input date. I need to be able to select the most recent clothes size for each item of clothing for each employee.

It is not necessary for all the columns to hold values because an employee could receive trousers or poloshirts at different times in the year.

So for example if employee '54664LSS' was given a pair of 'XL' trousers and a 'L' top on 24/03/11 but then received a 'M' top on 26/05/10. The input of these items would be help on two different rows obviously. So if I wanted to select the most recent clothing for each clothes category. Then the values of the 'M' sized top and the 'L' sized trousers would need to be returned.

Any help would be greatly appreciated as I'm pretty stuck :(. Thanks.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server