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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Order ID for latest order for every customer

Author  Topic 

assafjak
Starting Member

1 Post

Posted - 2008-01-08 : 17:01:25
Hi!
For the Orders table (let's assume for the Northwind database), I'm trying
to get the order id of the latest order for every customer.
That means that the result should be one record per customer and that would
display CustomerID and OrderID.

Any ideas?

Thanks,
Assaf

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2008-01-08 : 17:24:50
Do a GROUP BY on Customer and MAX on OrderId. IF you still have trouble post the query you have tried and someone can help you out...

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

pleitch
Starting Member

8 Posts

Posted - 2008-01-09 : 21:58:22
Is the column an index seed?

There are several functions for this if it is. Using these functions should be quicker than doing a "Max".
Go to Top of Page
   

- Advertisement -