sql - Update table using newest value in another table -


so had bit of issue entire tables unique "crc" set "n/a", luckily have table stored multiple versions of "crc" , if use should able pull original "crc"s

my basic concept is

update table1 set table1.crc = history.crc table1 join history on table1.phonenum = history.phonenum table1.field2 = 'uniquefield2 here' 

the problem don't know crc's being pulled

i want pull newest history.crc based on column "calldatetime" , update table1.crc value

source of query above update table based on values in table parameters

if have id field can search maximum id , return rows highest id, grouped on field wish.

i used inline view here maximum ids per phonenum:

update table1 set    table1.crc = history.crc   table1 join   history on     table1.phonenum = history.phonenum join   ( select phonenum          ,      max(id) id            history          group              phonenum        )        history_max on     history.id = history_max.id  table1.field2 = 'uniquefield2 here' 

Comments