sql - Find last match with latest inserted name in table -
sql - Find last match with latest inserted name in table -
i have table personalinfo
having columns such id, name, address
.
suppose have next data
1 john 2 mark uk 3 john uk 4 david
now when insert next new record
5 john china
i want update lastly record having same name new 1 illustration shown here record 3 john uk
updated 3 john china
.
when insert 5th record table should
1 john 2 mark uk 3 john china 4 david 5 john china
what sql query should use?
assuming id auto-incremented, highest value name , address combination.
update personalinfo set address = 'us' id = (select max(id) personalinfo name = 'john' , address = 'uk' )
sql sql-server
Comments
Post a Comment