title: SQL Update after Joining Two Tables
body: <p>I am new to SQL, using Microsoft SQL Server Management Studio.</p>
  
  <p>I am trying to write a SQL statement that performs an update after two tables are joined.</p>
  
  <p>I have two tables: <code>myTable1</code> and <code>myTable2</code>. Both share a field <code>MyID</code>, which is going to be the field that I join on. <code>myTable1</code> contains a column called <code>BitToUpdate</code>. And MyTable2 contains a column called <code>BitToCheck</code>.</p>
  
  <p>I want to set <code>BitToUpdate</code> in <code>myTable1</code> to be 1 where <code>BitToCheck</code> in <code>myTable2</code> is 1 as well.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>SELECT M.MyID, BitToUpdate, BitToCheck
  INTO #temp_table
  FROM myTable1 as T1
  LEFT JOIN myTable2 as T2
  ON M.MyId = PO.MyId
  </code></pre>
  
  <p>So first I tried to join the two tables <code>myTable1</code> and <code>myTable2</code> on their IDs, and store the result in a temporary table.</p>
  
  <p>Next, I want to update <code>BitToUpdate</code> to be 1 where <code>BitToCheck</code> is 1.</p>
  
  <p>So to do that in the temporary table, I have:</p>
  
  <pre><code>UPDATE #temp_table
  SET 
      `BitToUpdate` = 1
  WHERE
      `BitToCheck` = 1
  </code></pre>
  
  <p>This updates the <code>BitToUpdate</code> successfully in #temp_table. However, when I do a select on <code>myTable1</code>, I find that <code>BitToUpdate</code> is not changed. I suppose this makes sense as #temp_table isn't really a "pointer"....</p>
  
  <p>But what would be the correct way to approach this join and update?</p>