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)
 update query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-03-10 : 07:47:58
Fritz writes "Hi Guys, I want to update the rows in Table ONE from table TWO where table TWO holds multiple records that match the key of Table ONE, but I only want to use the newest records in Table TWO. I do have a datetime stamp on eah record in Table TWO.

Thanks
Fritz"

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-03-10 : 08:06:55
update t1
set col1 = t2.col1
--, other columns to update
from ONE t1
inner join TWO t2 on t1.id = t2.id
inner join (select id, max(DateCol) as DateCol from TWO group by id) t3 on t2.id = t3.id and t2.DateCol = t3.DateCol

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -