title: WHERE and JOIN order of operation
body: <p>My question is similar to this <a href="https://stackoverflow.com/questions/879893/sql-order-of-operations">SQL order of operations</a> but with a little twist, so I think it's fair to ask.</p>
  
  <p>I'm using Teradata. And I have 2 tables:  <code>table1</code>, <code>table2</code>.</p>
  
  <p><code>table1</code> has only an <code>id</code> column.<br>
  <code>table2</code> has the following columns: <code>id</code>, <code>val</code> </p>
  
  <p>I might be wrong but I think these two statements give the same results.</p>
  
  <p>Statement 1.</p>
  
  <pre><code>SELECT table1.id, table2.val
  FROM table1
  INNER  JOIN table2
  ON table1.id = table2.id
  WHERE table2.val&lt;100
  </code></pre>
  
  <p>Statement 2.</p>
  
  <pre><code>SELECT table1.id, table3.val
  FROM table1
  INNER JOIN (
      SELECT *
      FROM table2
      WHERE val&lt;100
  )  table3
  ON table1.id=table3.id
  </code></pre>
  
  <p>My questions is, will the query optimizer be smart enough to<br>
  - execute the WHERE clause first then JOIN later in Statement 1<br>
  - know that table 3 isn't actually needed in Statement 2</p>
  
  <p>I'm pretty new to SQL, so please educate me if I'm misunderstanding anything.</p>