title: Joining parents in 2 tables on exact match of child row values
body: <p>I have 2 table with below structure :</p>
  
  <p>Table 1 (Tb1) :</p>
  
  <pre><code>MasId Int, ItemId int, Quantity int
  1          1           10
  1          2           5
  1          3           18
  2          2           3
  2          4           8
  </code></pre>
  
  <p>Table 2 (Tb2) :</p>
  
  <pre><code>MasId Int, ItemId int, Quantity int
  10          1           10
  10          2           5
  10          3           18
  6           2           3
  6           4           8
  </code></pre>
  
  <p>I want to match Tb1 with Tb2 with <code>ItemId</code> and <code>Quantity</code> Columns. and get below query :</p>
  
  <pre><code>Tb1.MasId   Tb2.MasId
  1           10
  2           6
  </code></pre>
  
  <p>Table1 and Table2 contain about 2000000 record. and I use <code>SQL Server 2012</code></p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>In Tb1 and Tb2 exists records such below :</p>
  
  <p>Tb1:</p>
  
  <pre><code>MasId, ItemId, Quantity
  3      15       10
  3      16       2
  </code></pre>
  
  <p>Tb2:</p>
  
  <pre><code>MasId, ItemId, Quantity
  20     15      10
  20     18      5
  </code></pre>
  
  <p>Tb1.MasId and Tb2.MasId is not matched together.</p>