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 |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2009-08-03 : 14:42:56
|
| I have customers table and then customertransactions I want to query all customers and the last custormertransactions.name of the last record entered in cutomertranactionshow do I do this? |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-08-03 : 14:55:47
|
This code assumes the tables are correlated by [CustomerID] and the transaction table has a [transactionDate] column and that is what determines the "last" transaction:select c.* ,oa.*from customers couter apply ( select top 1 * from customerTransactions where customerid = c.customerid order by trasactionDate desc ) oa Be One with the OptimizerTGEDIT:and you should replace the "SELECT *"s with explicit column lists |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2009-08-03 : 15:11:27
|
| thanks :) |
 |
|
|
|
|
|