title: updating million rows based on resultset from previous query
body: <p>I need to update a table consisting of million rows</p>
  
  <p>there are two tables table1 and table2</p>
  
  <pre><code>SELECT ID
  FROM (
  select ID from table1 where&lt;condition&gt;
  ) as result1
  INNER JOIN table2 ON result1.field=table2.field 
  GROUPBY table2.field 
  HAVING &lt;condtion&gt;
  </code></pre>
  
  <p>and on this @resultset1 ID, I have to update table 1</p>
  
  <pre><code>UPDATE table1
  SET x=true
  where ID EXISTS IN (@resultset1)
  </code></pre>
  
  <p>there are millions of rows in both table. how do i do it?</p>
  
  <p>And Can anyone say whats wrong with this, i am trying some alternative over join</p>
  
  <pre><code>UPDATE table1 t1
  SET x=true
  WHERE &lt;condition&gt; AND EXISTS(
      SELECT* FROM (
          SELECT *
          FROM table2 t2
          WHERE t2.field =  t1.field 
      ) AS result 
  WHERE&lt;condition on resultset field&gt;
  );
  </code></pre>