title: SQL query - Join that returns the first two records of joining table
body: <p>I have two tables:</p>
  
  <p><strong>Patient</strong> </p>
  
  <ul>
  <li>pkPatientId</li>
  <li>FirstName</li>
  <li>Surname</li>
  </ul>
  
  <p><strong>PatientStatus</strong></p>
  
  <ul>
  <li>pkPatientStatusId</li>
  <li>fkPatientId</li>
  <li>StatusCode</li>
  <li>StartDate</li>
  <li>EndDate</li>
  </ul>
  
  <p><strong>Patient</strong> -> <strong>PatientStatus</strong> is a one to many relationship.</p>
  
  <p>I am wondering if its possible in SQL to do a join which returns only the first two PatientStatus records for each Patient. If only one PatientStatus record exists then this should not be returned in the results.</p>
  
  <p>The normal join of my query is:</p>
  
  <pre><code>SELECT FROM Patient p INNER JOIN PatientStatus ps ON p.pkPatientId = ps.fkPatientId
  ORDER BY ps.fkPatientId, ps.StartDate
  </code></pre>