Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Having Trouble With a Query
Message
From
05/02/2009 15:44:12
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01097119
Message ID:
01379630
Views:
19
Jeez, Naomi ... this post you're replying to was 3 years old! Plus, it looks like I already had it answered. I don't even remember what Stored Proc I was working on when I posted the question. So I guess I can't even try your suggestion.

~~Bonnie


>Hi Bonnie,
>
>Try
>
>select PK, FK, Date from (select Date, PK, FK, row_number() 
>OVER (partition by FK order by Date DESC) as rn) MaxDates where rn = 1
>
>>I have two tables, one with a date, PK and a FK to the second table. I need to select the latest date and the two keys for every group of FK's. If my data is this:
>>
>>Date         PK          FK
>>1/1/2001     1           1
>>1/5/2002     2           1
>>2/2/2001     3           1
>>6/6/2005     4           2
>>1/1/2005     5           2
>>
>>Then I'd like my output to look like this:
>>
>>Date         PK          FK
>>1/5/2002     2           1
>>6/6/2005     4           2
>>
>>I'm having trouble coming up with a query to do this. Any ideas?
>>
>>TIA,
>>~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform