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)
 Selecting based on max time stamp

Author  Topic 

sness
Starting Member

7 Posts

Posted - 2007-01-12 : 17:06:27
I'm trying to find the syntax to select a unique value based on the max from a time stamp. In tbl1 I have order_nbr and time_stamp. There will be multiple records with the same order_nbr, but with a different time_stamp value. How do I select only the order_nbr with the max time_stamp value?

Thanks.

sness
Starting Member

7 Posts

Posted - 2007-01-12 : 17:16:16
Sorry, just realized that post was not written very well. Forgot to add that there are also fields item and sales. So, for each order_number, I need to select order_number, item, sales for only the record with the max time_stamp.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-12 : 21:33:43
[code]
select *
from tbl1 t
where time_stamp = (select max(time_stamp) from tbl1 x where x.order_number = t.order_number)
[/code]


KH

Go to Top of Page

sness
Starting Member

7 Posts

Posted - 2007-01-12 : 22:35:28
Thanks.
Go to Top of Page
   

- Advertisement -