January 27, 2011 at 12:11 pm
Here's my data:
EmpId Date
11/18/2011 6:30:00 AM
11/18/2011 4:45:00 PM
21/18/2011 2:00:00 PM
21/18/2011 8:45:00 PM
31/18/2011 9:00:00 AM
31/18/2011 5:00:00 PM
All I'm trying to do is return one record per empid with the minimum date, ex:
EmpId Date
11/18/2011 6:30:00 AM
21/18/2011 2:00:00 PM
31/18/2011 9:00:00 AM
Does anyone have some suggestions on how I could go about doing this? I'm thinking about using a subquery but I haven't had much luck so far
Select empid,
(select min(date)
from table
--would I need to add a self join here?
From table
Any suggestions would be greatly appreciated
January 27, 2011 at 12:19 pm
select EmpID, min(Date)
from MyTable
group by EmpID;
Does that do what you need?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
January 27, 2011 at 6:17 pm
Ahh yes that's it. I was grouping by the wrong column. Thank you.
January 28, 2011 at 6:22 am
You're welcome.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply