How do I Update record from different record in same table

  • I have the following data

    ID LastName First Name Telephone Address

    1 Smith Joe 1 Main Street

    2 Smith Joe 444-444-4344

    The records above are referencing the same person so I want to update record 1 with some of the data in record 2 and then I will delete record 2. I'd like something like

    UPDATE table

    Set Telephone = (Telephone from Record ID 2)

    FROM table

    ...

    I've searched all over and can't find a solution other than, UPDATE table set Telephone = '444...)

    FROM Table where ID = 1

  • create table mytable (id int, firstname varchar(10), lastname varchar(10), tele varchar(10))

    go

    insert mytable select 1, 'John', 'Smith', ''

    insert mytable select 2, 'John', 'Smith', '5553333333'

    go

    select * from mytable

    go

    update a

    set a.tele = b.tele

    from mytable a

    inner join mytable b

    on a.id = 1 and b.id = 2

    go

    select * from mytable

    go

    drop table mytable

  • Excellent. Exactly what I needed. Thanks SSChampion.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply