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 |
|
tbstar
Starting Member
2 Posts |
Posted - 2008-12-01 : 13:43:07
|
| Hi all,I have two tables one to many, the client_tbl and client_history_tbl are linked with client_tbl_key. the child table holds history of service changes. now I would like to get all the clients that have a specific service, let's say 10 but I can't get the data that I want. Why? Because when I try Max of the date or the primary key of the child table, it doesn't give me the latest entry. I would've used Access Last function but it's not there. Any clue?Clientspk1pk2pk3Servicespk1, fk1, 11/1/2008 1:30, 15pk2, fk1, 11/10/2008 1:33, 10pk3, fk1, 11/19/2008 1:34, 11pk4, fk1, 12/1/2008 1:36, 20pk5, fk1, 12/1/2008 1:38, 10The result should look like this:pk1, fk5Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-01 : 23:50:10
|
| [code]SELECT c.PK,s.PK,s.Date,s.ValueFROM (SELECT ROW_NUMBER() OVER (PARTITION BY c.PK ORDER BY h.Date DESC) AS Seq,*FROM Clients cINNER JOIN Services sON s.FK=c.PK)tWHERE t.Seq=1[/code] |
 |
|
|
tbstar
Starting Member
2 Posts |
Posted - 2008-12-09 : 12:10:26
|
| I found my way through using your approach, thanks a lot |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-09 : 12:14:19
|
welcome |
 |
|
|
|
|
|
|
|