title: In MySQL I need to retrieve artist with highest points by location
body: <p>In MySQL I need to get artist with highest points by location. Please help.</p>
  
  <p><strong>user_location_tbl (user location table)</strong></p>
  
  <pre><code>|--------------------------------------|
  | countryLat | countryLong  |  userid  |
  |--------------------------------------|
  | 31.695766  | 54.624023    |  1       |
  | 20.593684  | 78.96288     |  2       |
  | 20.593684  | 78.96288     |  3       |
  | 20.593684  | 78.96288     |  4       |
  | 31.695766  | 54.624023    |  5       |
  |--------------------------------------|
  </code></pre>
  
  <p><strong>fans_table (to view which artist has which user as a fan)</strong></p>
  
  <pre><code>|----------------------|----------
  | artist_id  | user_id |  Points |   
  |----------------------|----------
  | 1          | 1       |    20    |
  | 1          | 2       |    30    |
  | 2          | 1       |    40    |
  | 2          | 3       |    40    |   
  | 3          | 1       |    60    |
  |----------------------|----------
  </code></pre>
  
  <p><strong>artist_table (list of artist)</strong></p>
  
  <pre><code>|-------------------|
  | artistid | name   |
  |-------------------|
  | 1        | raja   | 
  | 2        | sekar  |
  | 3        | thomas |
  |-------------------|
  </code></pre>
  
  <p>I need to get location wise which artist is having highest point but I can't do it in a single query. If I put sum(points) and group by countryLat, countryLong, artistid, I get the following result...</p>
  
  <pre><code>|---------------------------------|
  | 100 | 20.593684 | 78.96288  | 1 |
  | 50  | 20.593684 | 78.96288  | 2 |
  | 100 | 31.695766 | 54.624023 | 3 |
  | 90  | 31.695766 | 54.624023 | 1 |
  |---------------------------------|
  </code></pre>
  
  <p>...but I only need the artist with highest point on that location as in the example below...</p>
  
  <pre><code>|---------------------------------|
  | 100 | 20.593684 | 78.96288  | 1 |
  | 100 | 31.695766 | 54.624023 | 3 |
  |---------------------------------|
  </code></pre>
  
  <p>SQL</p>
  
  <pre><code>SELECT Sum(c.tot_points), 
         a.artist_id 
  FROM   `fans_table` AS a 
         INNER JOIN `user_location_tbl` AS b 
                 ON a.user_id = b.user_id 
         INNER JOIN artist_table AS c 
                 ON a.artist_id = c.id 
  GROUP  BY b.countrylat, 
            b.countrylong, 
            a.artist_id 
  </code></pre>
  
  <p>Above is my query</p>