title: How do I reference the MIN SQL function in my WHERE clause using a subtable?
body: <p>I have a table of lastNames and userNames. I want the 'smallest' (lexically speaking) value for a lastName and the corresponding userName. This is what I have (and this works):</p>
  
  <pre><code>SELECT lastName, userName FROM user  WHERE lastName IN (SELECT MIN(lastName) FROM user);
  </code></pre>
  
  <p>Now I want to do this but do it on a subset of the table (for example, only for the lastNames starting with 'P'):</p>
  
  <pre><code>SELECT subT.lastName, subT.userName
  FROM (SELECT lastName, userName FROM user WHERE lastName LIKE 'p%') AS subT
  WHERE subT.lastName=MIN(subT.lastName)
  </code></pre>
  
  <p>This doesn't work. I tried to put the MIN function as a select_item but I also want the userName that corresponds with the MIN function. How do I do this?</p>