title: SQL Server inner join and subquery
body: <p>I have below the query that updates certain ids on <code>HierarchicalTable</code>.</p>
  
  <p>My first query, is stable but I have a problem on its performance:</p>
  
  <pre><code>DECLARE @targetName varchar(100)
  UPDATE a
  SET   a.PrimaryId = b.PrimaryId
      , a.SecondaryId = b.SecondaryId
  FROM
  (
      SELECT PrimaryId
           , SecondaryId
      FROM Hierarchical
      WHERE ParentName = @targetName
  ) as a
  JOIN 
  (
      SELECT PrimaryId
           , SecondaryId
      FROM Hierarchical
      WHERE Name = @targetName
  ) b
  ON a.ParentId = b.Id
  </code></pre>
  
  <p>This next query, is my second option:</p>
  
  <pre><code>DECLARE @targetName varchar(100)
  
  UPDATE a
  SET   a.PrimaryId = b.PrimaryId
      , a.SecondaryId = b.SecondaryId
  FROM Hierarchical a
  JOIN Hierarchical b
  ON a.ParentId = b.Id
  WHERE a.ParentName = @targetName
    AND b.Name = @targetName
  </code></pre>
  
  <p>My questions are: </p>
  
  <ol>
  <li><p>Does the second query execute just like the first query?</p></li>
  <li><p>Will the second query outperform the first query?</p></li>
  </ol>
  
  <p>*Note: I have large scale of data, and we're having hardware issues on executing 
  these queries.</p>
  
  <p>I've posted here at SO so that I can have any opinions that I can see.</p>