title: Writing a LIMIT subquery within my SQL query
body: <p>So I have the following query which fetches active competitions for an organisation, but also aims to fetch the user that is in the lead - for each competition fetched. </p>
  
  <p>The query currently works in that it fetches the competitions, however it currently fetches all the users and I would like to LIMIT 1 on the users fetched, using the SUM(activity_weight) you can see below. </p>
  
  <p>The results come out like this (removed some results to make it easy to see) and in my case, I only want to fetch <strong>John and Sally</strong>, as they are the leaders of the competitions. </p>
  
  <pre><code>competitionId  compName  start_date  end_date  name  totalPoints
  ------------------------------------------------------------
  123           First Comp   13-09-09  13-10-09  John    100
  123           First Comp   13-09-09  13-10-09  Bob     50
  431           Second Comp  13-05-04  13-10-05  Sally   500
  431           Second Comp  13-05-04  13-10-05  Jessica 50
  </code></pre>
  
  <p>I understand that I must use some form of subquery to use the LIMIT, but having a problem nailing the syntax of it.</p>
  
  <p>Any help is much appreciated! THANK YOU</p>
  
  <pre><code>  SELECT c.competitionId, c.name, c.start_date, c.end_date, a.userid, u.name, 
    u.profilePic , 
    SUM(activity_weight) AS totalPoints
  
    FROM activity_entries a INNER JOIN users1 u ON u.id = a.userid 
    INNER JOIN competitions c  ON c.competitionId = a.competitionId
  
    WHERE c.organisationId = '$organisation' AND c.start_date &lt; now() AND c.end_date &gt; now()  
    GROUP BY a.userid, c.competitionId ORDER BY c.id DESC, totalPoints DESC
  </code></pre>