title: SQL - Filtering large tables with joins - best practices
body: <p>I have a table with a lot of data and I need to join it with some other large tables.</p>
  
  <p>Only a small portion of my table is actually relevant for me each time.</p>
  
  <p>When is it best to filter my data?</p>
  
  <ol>
  <li><p>In the where clause of the SQL.</p></li>
  <li><p>Create a temp table with the specific data and only then join it.</p></li>
  <li><p>Add the predicate to the first inner join ON clause.</p></li>
  <li><p>Some other idea.</p></li>
  </ol>
  
  <p>1.</p>
  
  <pre><code>Select * 
  From RealyBigTable
  Inner Join AnotherBigTable On …
  Inner Join YetAnotherBigTable On …
  Where RealyBigTable.Type = ?
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>Select * 
  Into #temp
  From RealyBigTable
  Where RealyBigTable.Type = ?
  
  Select * 
  From #temp
  Inner Join AnotherBigTable On …
  Inner Join YetAnotherBigTable On …
  </code></pre>
  
  <p>3.</p>
  
  <pre><code>Select * 
  From RealyBigTable
  Inner Join AnotherBigTable On RealyBigTable.type = ? And … 
  Inner Join YetAnotherBigTable On …
  </code></pre>
  
  <p>Another question:
  What happens first? <code>Join</code> or <code>Where</code>?</p>