|
jpheep
Starting Member
1 Post |
Posted - 2011-05-17 : 14:15:29
|
| Hi,I've been trying a while but couldn't find a solution that works for me. I have a single table that has columns for Interview_Date, Candidate_ID, Position_ID, and Interview_ID.What I am trying to do is select the two most recent records for each unique combination of Candidate_ID and Position_ID.So if my table has the following:Candidate_ID, Position_ID, Interview_ID, Interview_DateCan001, Pos001, Int001, 1/1/2011Can001, Pos001, Int002, 1/2/2011Can001, Pos001, Int003, 1/3/2011Can001, Pos002, Int004, 1/1/2011Can001, Pos002, Int005, 1/4/2011Can001, Pos002, Int006, 1/5/2011Can002, Pos003, Int007, 1/1/2011Can002, Pos003, Int008, 1/2/2011Can002, Pos003, Int009, 1/3/2011Can002, Pos002, Int010, 1/1/2011Can002, Pos002, Int011, 1/4/2011Can002, Pos002, Int012, 1/5/2011I want the result to be:Can001, Pos001, Int002, 1/2/2011Can001, Pos001, Int003, 1/3/2011Can001, Pos002, Int005, 1/4/2011Can001, Pos002, Int006, 1/5/2011Can002, Pos003, Int008, 1/2/2011Can002, Pos003, Int009, 1/3/2011Can002, Pos002, Int011, 1/4/2011Can002, Pos002, Int012, 1/5/2011I have tried the following without much luck:Select S.position_id, S.candidate_id, S.interview_date From interviews SWhere (Select Count(*) From interviews Where Interview_Id = S.interview_id And interview_date > S.interview_date) < 2 |
|