Can we use UPDATE with joins

  • Hi All,

    Yesterday i was asked a question regarding join and i told them that but after that the other question was can we use joins in update, i said no(with my knowledge). I want to know that i am correct or not.Please update me.

    Thanks in advance,

    Syed Sanaullah Khadri

    DBA

  • Sure you can. It's actually a rather common operation in my shop.

    UPDATE TableA

    SET TableA.columnA=TableB.ColumnB

    FROM TableA

    INNER JOIN TableB ON TableA.ID=TableB.ID

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Thanks Matt,

    i have used joins may times but only to select not for update.

    Will it work with insert and delete also.

  • [font="Verdana"]Obviously.

    For Delete:

    Delete From A Inner Join B On A.Id = B.Id

    For Insert in different way like:

    Insert Into A (col1, Col2)

    Select B.Col1, C.Col2 From B Inner Join C On B.Id = C.Id

    Mahesh

    [/font]

    MH-09-AM-8694

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

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