tags:

views:

20

answers:

1

Is it possible to select a list of rows from this table format based on distinct fk2 and > date?

Table

pk fk1 fk2 value date

1 1 1 100 1/1/2009

2 1 2 110 1/1/2009

3 1 2 120 5/1/2009

4 1 3 130 1/1/2009

I would like it to return rows 1,3,4

I only pass in fk1

Select * from table where fk1=1 'and the row with the latest date for each fk2?

Regards

+2  A: 
Select * from table t where t.fk1=1 and t.date=( select max(date) from table where fk2=t.fk2 and fk1=t.fk1)
x2
thanks! That did it