title: SQL Update Statement Using Join
body: <p>I am trying to update a row in a database. I am uploading data into a temp table through my program and then moving that data to the main table after it has been converted. For example I upload a file into my temp table which has 2 rows: First row is Personal ID and the second is shoe brand, with the shoe brand being the primary key. I also have a shoe brand table where say Nike is row 1, Adidas row 2, Reebok row 3 and Shoe_Brand_Name is the name of the column with the name and Shoe_Brand_ID is the ID associated with the name. </p>
  
  <p>When I upload my data to my temp table it will look like this:</p>
  
  <pre><code>              TEMP_TBL
  
  Personal ID              Shoe Brand
    123456                    Nike
  </code></pre>
  
  <p>But when I move it to my main table I am using an insert with left outer join and the same data as above in the main table will look like this:</p>
  
  <pre><code>              MAIN_TBL
  
  Personal ID              Shoe_Brand
    123456                      1
  </code></pre>
  
  <p>Here is where my problem comes in. Say the user uploads another file with the same Personal ID, and the difference is the shoe brand changes from Nike to Reebok. I would need the main table to update to this:</p>
  
  <pre><code>         MAIN_TBL (After Update)
  
   Personal ID              Shoe_Brand
    123456                      3
  </code></pre>
  
  <p>Here is the code I am trying to run:</p>
  
  <pre><code>UPDATE [MAIN_TBL]
  SET [Shoe_Brand] = b.[Shoe_Brand_ID]
  
  FROM [TEMP_TBL] a
  left outer join [MAIN_TBL].tbl_shoebrand b on (a.[Shoe Brand] = b.Shoe_Brand_Name)
  
  WHERE [Personal ID] = '123456'
  </code></pre>
  
  <p>This code runs, but does nothing..... literally nothing.</p>
  
  <p>Can anyone give me some advice?</p>