title: Only want the first if several matches are returned
body: <p>I have an SQL script that returns a number of records. This is the code:</p>
  
  <pre><code>select distinct eb.exerciseindex, eb.exercisestarttime, AVG(pb.playerbirthyear) as Birthavg, COUNT(pb.playerindex) as playersinexercise, pb.playersex from playerbase as pb
  inner join exbase as ex on ex.explayerindex = pb.playerindex
  inner join exercisebase as eb on eb.exerciseindex = ex.exexerciseindex
  where exerciseallowanceindex='B26E10C5-53E1-413A-8A49-A7088D33E690'
  and exercise_is_paying='true'
  group by exercisestarttime, pb.playersex, eb.exerciseindex 
  order by exerciseindex, playersinexercise desc
  </code></pre>
  
  <p>I have attached an image with the results.</p>
  
  <p>Now, what I want is a kind of DISTINCT on the results. If you note, on some occasions several rows are returned for the same EXERCISEINDEX (see row 1 and 2 for example). But what I need is that only the FIRST row for this exerciseindex is returned (the one with the higher PLAYERCOUNT).</p>
  
  <p>Any ideas how this can be done?</p>
  
  <p>Regards,</p>
  
  <p>Bob</p>
  
  <p><img src="https://i.stack.imgur.com/nGEfG.png" alt="returned sql"></p>