title: Difference between cross apply and inner join based on below example
body: <p>Below  I have Two tables #temp and #temp2. </p>
  
  <pre><code> create table #temp
      (
       col1 int
       )
  
       insert into #temp values(6),(1),(2),(3),(null)
  
  
  
       create table #temp2
       (
         col1 int
         )
         insert into #temp2 values(1),(2),(1),(2),(3),(null)
  </code></pre>
  
  <p>And also i have two queries below
  With INNER JOIN:</p>
  
  <pre><code> SELECT t1.col1,
             Sum(t2.col1) AS col1
      FROM   #temp t1
             INNER JOIN #temp2 t2
                     ON t1.col1 = t2.col1
      GROUP  BY t1.col1
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>col1    col1
  1        2
  2        4
  3        3
  </code></pre>
  
  <p>And second query is </p>
  
  <p>With CROSS APPLY:</p>
  
  <pre><code>SELECT *
  FROM   #temp t1
         CROSS apply (SELECT Sum(col1) AS col1
                      FROM   #temp2 t2
                      WHERE  t1.col1 = t2.col1) A
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>col1    col1
  1        2
  2        4
  3        3
  6       NULL
  </code></pre>
  
  <p>Now, I want to know the difference between CROSS APPLY and INNER JOIN. I Know CROSS APPLY similar like INNER JOIN For each and Every record of #temp(first table) cross apply will execute.But I am getting Different Result Set based on above result sets  Can any one Please Explain?</p>
  
  <p>Thanks in advance.</p>