Results 1 to 2 of 2

Thread: SQL Update Join

  1. #1
    Join Date
    Jan 2012

    Post Unanswered: SQL Update Join

    have any one know SQL Update Join training material with live example. Pls help us..

  2. #2
    Join Date
    Nov 2004
    Provided Answers: 4
    This is the general form.
    SET U.AColumn = OtherTable.AnOtherColumn
    FROM TableToUpdate AS U
       INNER JOIN OtherTable On
          U.YetAnotherColumn = OtherTable.YetAnotherColumn 
       INNER JOIN ATotallyDifferentTable On
          OtherTable.NutherColumn = ATotallyDifferentTable.NutherColumn
    WHERE ATotallyDifferentTable.SomeColumn NOT IN ('Yea', 'Nay', 'Dunno')
    I find it a good habit to give the table that will be updated the alias name "U", to distinguish it from the other tables.

    Basically you write the JOINS (INNER, LEFT OUTER, ...) and WHERE clause like you would for any SELECT statement. In the SET part, you can assign a literal value to the update column (like U.IsActive = 'N') , or any column from one of the JOINed tables (U.AColumn = OtherTable.AnOtherColumn).

    If the article you mentioned, you will find a similar example under the header "SQL Update Join".
    With kind regards . . . . . SQL Server 2000/2005/2012

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts