May 16, 2013 at 6:50 am
I have three fields I am interested in:
Employee_ID,
Employee_Title,
Employee_Entry
I want to be able to select these three fields but only the record with the most recent Employee_Entry date. In some cases an Employee may have moved job titles and have several entries against the Employee_ID.
I have started with something like this:
SELECT DISTINCT
Employee_ID,
Employee_Title,
Employee_Entry
FROM emp.employees
I have tried using Max(Employee_Entry) but this returns all records for those who have multiple titles. I just want the current most recent Employee_title.
May 16, 2013 at 6:54 am
i think using the row number with a sub select will get you what you are after:
SELECT
Employee_ID,
Employee_Title,
Employee_Entry
FROM (SELECT
ROW_NUMBER() OVER (partition BY Employee_ID ORDER BY Employee_Entry DESC) AS RW,
Employee_ID,
Employee_Title,
Employee_Entry
FROM emp.employees) myAlias
WHERE RW = 1
Lowell
May 16, 2013 at 6:58 am
That did it.
Thank you.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply