title: Get one row for each group with order and limit
body: <p>I have records of photos that users have uploaded in my database. They can specify one of the photos they have uploaded as being a cover photo. </p>
  
  <p>I'd like to query my database to return one photo for each username. If they have cover photo, return that one. If not, pull a normal photo. The column to specify a cover photo is tinyint with a length of 1. The column is either "0"(not a cover photo) or "1"(a cover photo). </p>
  
  <p>I have the following to return all photos for the list of usernames</p>
  
  <pre><code>$usernames = array('bob', 'ted', 'jim');
  $usernames = implode( "', '", $usernames );
  
  $query = "SELECT * FROM Photos WHERE username IN('$usernames')";
  </code></pre>
  
  <p>but i need to combine it with the following, which gets a cover photo if there is one and a normal photo if there isn't for one username.</p>
  
  <pre><code>$query = "SELECT * FROM Photos WHERE username = 'bob' ORDER BY cover DESC LIMIT 1";
  </code></pre>
  
  <p>I think I need to use the GROUP BY function but I don't know how to set that up. Any suggestions?</p>
  
  <p>Columns are id(bigint), name(varchar(255)), cover(tinyint), username(varchar(30))</p>