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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-07-14 : 08:53:04
|
| Brandon writes "I have a table containing columns for cutomerid and orderdate. there are multiple orders for each customer in this table. I need to produce a unique list of customers with the last date they ordered something. The Top command really doesn't do this on a per customerid basis. I can try to link a few queries together to try to accomplish this, but it would mean a separate call for each individual customerid to retrieve the top 1 order sorted by orderdate desc. There are thousands of customers. There must be a better way. Any ideas?" |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2006-07-14 : 08:53:28
|
| SELECT customerid, max(orderdate) AS LastOrderDate FROM myTable GROUP BY customerid |
 |
|
|
|
|
|