title: How to select top 3 values from each group in a table with SQL which have duplicates
body: <p>Assume we have a table which has two columns, one column contains the names of some people and the other column contains some values related to each person. One person can have more than one value. Each value has a numeric type. The question is we want to select the top 3 values for each person from the table. If one person has less than 3 values, we select all the values for that person. </p>
  
  <p>The issue can be solved if there are no duplicates in the table by the query provided in this article <a href="http://www.pixelstech.net/article/1369297243_Select_top_3_values_from_each_group_in_a_table_with_SQL" rel="noreferrer">Select top 3 values from each group in a table with SQL </a> . But if there are duplicates, what is the solution? </p>
  
  <p>For example, if for one name John, he has 5 values related to him. They are 20,7,7,7,4. I need to return the name/value pairs as below order by value descending for each name:</p>
  
  <pre><code>-----------+-------+
  | name     | value |
  -----------+-------+
  | John     |    20 |
  | John     |     7 |
  | John     |     7 |
  -----------+-------+
  </code></pre>
  
  <p>Only 3 rows should be returned for John even though there are three 7s for John.</p>