Friday, March 9, 2012

Help with Query

I am struggling to build the appropriate query for the following scenario. A
simplified version of my problem is... consider the following table
EEID EPID StartDate
1 11 1/1/2005
1 13 2/1/2005 *
2 13 1/1/2005 *
3 14 2/1/2005
3 11 4/1/2005 *
The star indicates the records that should be pulled, and I need all 3
fields. The condition is, for each EEID pull the record with the largest
date.
If i do something like
select EEID, max(StartDate) from table group by EEID
I get the appropriate row, but i am missing one field.
Please help. I have struggled long and hard on this one.
thank You.
PooravI am , what field are you missing?
Message posted via http://www.webservertalk.com|||Select * From Table T
Where StartDate = (Select Max(StartDate)
From Table
Where EEID = T.EEID)
"haiiyaa" wrote:

> I am struggling to build the appropriate query for the following scenario.
A
> simplified version of my problem is... consider the following table
> EEID EPID StartDate
> 1 11 1/1/2005
> 1 13 2/1/2005 *
> 2 13 1/1/2005 *
> 3 14 2/1/2005
> 3 11 4/1/2005 *
> The star indicates the records that should be pulled, and I need all 3
> fields. The condition is, for each EEID pull the record with the largest
> date.
> If i do something like
> select EEID, max(StartDate) from table group by EEID
> I get the appropriate row, but i am missing one field.
> Please help. I have struggled long and hard on this one.
> thank You.
> Poorav
>

No comments:

Post a Comment