Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
KingCarlos
Yak Posting Veteran
74 Posts |
Posted - 2011-05-25 : 00:13:20
|
| So here is my basic tablesTable ARecordID TableAID Date Value1 a1 1-1-11 abc2 a2 2-2-11 def3 a3 3-3-11 ghiTable BRecordID TableAID Date Value1 a1 2-2-11 x12 a1 3-3-11 x2 3 a1 4-4-11 x3 4 a2 10-2-11 x45 a2 13-2-11 x5 6 a3 5-5-11 x6I want to be able to run a query that returns the last value in Table B for the records in table A therefore have the following dataTableA.ID TableA.date, TableA.value TableB.date TableB.Summarya1 1-1-11 abc 4-4-11 x3 a2 2-2-11 def 13-2-11 x5 a3 3-3-11 ghi 5-5-11 x6Any advice? |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-05-25 : 02:06:28
|
selectTableA.ID TableA.date, TableA.value TableB.date TableB.Value as Summaryfrom Table_A as Ajoin(selectrow_number() over (partition by TableAID order by Date DESC) as rownum,*from Table_B)Bon B.TableAID = A.TableAID and B.rownum=1 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|