title: Top N per Group Sql problem in mysql
body: <p>Please I am having a problem querying  for the Top N per category from a data set resembling the one shown below. I have see various thread on this but I am having problem adapting their query to my specific problem.</p>
  
  <pre><code>+----+---------------------------------+-------+
  | ID | Prod                            |Cat Id |
  +----+---------------------------------+-------+
  |  1 |  kntrn                          |     1 |
  |  2 | kntrn e                         |     1 |
  |  3 | e spl                           |     1 |
  |  4 | spl php                         |     1 |
  |  5 | php cicarredgtal                |     1 |
  |  6 | cicarredgtal servecounterstrike |     1 |
  |  7 | servecounterstrike com          |     1 |
  |  8 |  zlv                            |     2 |
  |  9 | zlv enter                       |     2 |
  | 10 | spl php                         |     2 |
  +----+---------------------------------+-------+
  </code></pre>
  
  <p>I want to group based on this rule (1) Select Top 3 Prod for each catid.</p>
  
  <p>Please do note that top in this sense is the one highest count of prod in all category.</p>
  
  <p>So for the example above spl php is the highest for catID 1 because it occurs twice across all category. </p>