sql server - How to select info from the latest record from a table? -
i have table 1 like:
first name last name birthyear modifieddate john doe 1990 2/25/2011 john doe 1995 3/2/2011 where latest record (ie row birthyear 1995) contains recent accurate information.
i insert 'correct' latest birthyear table.
the original query wrote was: `
update table2 set birthyear = table1.birthyear table 1 join table 2 on table1.first_name = table2.first_name , table1.last_name = table2.last_name but inserts birthyear (1990) first record.
how modify query inserts correct "most recent" info?
with cross apply:
update t2 set birthyear = ca.birthyear table2 t2 cross apply(select top 1 birthyear table1 t1 t1.firstname = t2.firstname , t1.lastname = t2.lastname order t1.modifieddate desc) ca
Comments
Post a Comment