title: Android - SQLite Select the first N occurrences of each differing column value
body: <p>Suppose I have a SQL table "songs" with three columns: "title", "artist" and "ranking":</p>
  
  <pre><code> track   | artist | ranking     
  ---------+--------+---------  
      A    |   A1   |   3
      B    |   A1   |   2
      C    |   A1   |   1
      D    |   A2   |   4
      E    |   A3   |   7
      F    |   A3   |   6
      G    |   A3   |   5
  </code></pre>
  
  <p>I want to make a SELECT query that will return just the first N (e.g. two) row for each artist while ordering by the ranking. I'm aware that using GroupBy on the artist column will return one row of each artist, however I want two in this scenario like so:</p>
  
  <pre><code> track   | artist | ranking     
  ---------+--------+---------  
      A    |   A1   |   1
      B    |   A1   |   2
      D    |   A2   |   4
      E    |   A3   |   5
      F    |   A3   |   6
  </code></pre>
  
  <p>If it is possible, I would preferably want to construct this within android using a queryBuilder, this is as close as I managed to get:</p>
  
  <pre><code>SQLiteDatabase db = getReadableDatabase();
  SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder();
  
      String[] sqlSelect = {"title", "artist", "ranking"};
      String sqlTable = "songs";
      String orderBy = "ranking DESC";
  
      qBuilder.setTables(sqlTable);
      cur = qBuilder.query(db, sqlSelect, null, null, null, null, orderBy);
  </code></pre>
  
  <p>I have seen related questions, however I haven't been able to find a way to apply it to this scenario - any direction on how to accomplish this would be appreciated.</p>