title: sql performance - query design when fetching from multiple tables
body: <p>Ok, premise. Three tables, simple enough for this exercise:</p>
  
  <pre><code>table first:
  id, name
  
  table second:
  id, firstId, secondName
  
  table third
  id, thirdName, secondId
  </code></pre>
  
  <p>I want to take all rows in third that have a foreignkey to a row in the second that have a relation to a certain "first" row id.</p>
  
  <p>Typical sql:</p>
  
  <pre><code>select t.id, s.id as secondId, t.thirdName, s.secondName from third t 
  inner join second s on t.secondId=s.id where s.firstId = X
  </code></pre>
  
  <p>So here is my question:</p>
  
  <p>Would it be faster performance wise, to have a column in third instead that is a foreign key directly to first?</p>
  
  <p>i.e.</p>
  
  <pre><code>table third:
  id, secondId, firstId, name
  </code></pre>
  
  <p>So that i instead could make the query:</p>
  
  <pre><code>select t.id, s.id as secondId, t.thirdName, s.secondName from third t 
  inner join second s on t.secondId=s.id where t.firstId = X 
  </code></pre>
  
  <p>There are no less joins since i need the data from "second" too, but i'd make the lookup on "firstId" from third rather than second.</p>
  
  <p>Just curious if anybody has any input :)</p>