Home All Groups Group Topic Archive Search About
Author
13 May 2005 5:33 PM
haiiyaa
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

Author
13 May 2005 5:59 PM
Ian Galloway via SQLMonster.com
I am confused, what field are you missing?

--
Message posted via http://www.sqlmonster.com
Author
13 May 2005 6:04 PM
CBretana
Select * From Table  T
Where StartDate = (Select Max(StartDate)
                              From Table
                              Where EEID = T.EEID)

Show quote
"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
>

AddThis Social Bookmark Button