title: How to find the tallest patient in each ward
body: <p>I have two tables:</p>
  
  <p><code>patient (patient_id (PK), patient_name, gender, height, weight, staff_no, ward_no)</code></p>
  
  <p><code>ward (ward_no (PK), ward_name, number_of_beds)</code></p>
  
  <p>I want to find the tallest patient in each ward.</p>
  
  <p>This is my query:</p>
  
  <pre><code>Select patient_name, MAX(height) from patient Group By patient_name
  </code></pre>
  
  <p>Does this query work?</p>
  
  <p><strong>This is a mock exam question so I have the model answer.</strong></p>
  
  <pre><code>select patient_name 
  from patient p1 
  where not exists (select * from patient p2 where p1.ward_no = p2.ward_no and p1.height &lt; p2 .height) 
  </code></pre>
  
  <p>I don't understand the sub-query can some one explain it please.
  Thank you</p>