#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    151
    Rep Power
    5

    Insert into using join query


    Though my question seems to be vague, I think the solution is simple - please help
    I have three related tables and need to insert a field in table one using the field in table three and primary key is in table 2

    Example
    Table 1 fields - ID, rank
    Table 2 fields - ID, Name
    Table 3 Fields - Name, rank

    Now I want to insert the rank from the 3rd table into rank of table 1 using the ID and Name mapping in table 2.
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,262
    Rep Power
    4279
    Code:
    UPDATE table1
       SET rank = t3.rank
      FROM table1 AS t1
    INNER
      JOIN table2 AS t2
        ON t2.id = t1.id
    INNER
      JOIN table3 AS t3
        ON t3.name = t2.name
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    151
    Rep Power
    5
    It worked and I have updated 300K data. Thank you

IMN logo majestic logo threadwatch logo seochat tools logo