title: Find best picture for each category
body: <p>I have a database (mysql) with two tables, one for categories and one for photos. </p>
  
  <p>Not all categories have photos, but the ones with photos are marked in the categories table with a flag photo=yes. There is also a flag for the domestic categories, which are the ones I'm interested in here. The Photos have grades from 1-10. </p>
  
  <p>What I want to do is to rank the categories flagged domestic=yes with the worst photos (so I know what to improve). Since there are 700 categories and about 7.000 photos, it would be nice to search. :-) </p>
  
  <p>Categories Table</p>
  
  <pre><code>ID     Category_name    Photo    Domestic
  1      CatA             yes      yes
  2      CatB             yes      yes
  3      CatC             yes      yes
  4      CatD             yes      no
  5      CatE             no       yes
  </code></pre>
  
  <p>Photo table</p>
  
  <pre><code>ID    Cat_ID    Grade
  1     1         4
  2     1         4
  3     1         5
  4     2         6
  5     2         6
  6     3         4
  7     3         4
  8     3         3
  9     4         2
  </code></pre>
  
  <p>So the result from my search I would like to get is the domestic=yes categories that have photo=yes ranked by category with the worst best pic: </p>
  
  <pre><code>Category:    Grade:
  CatC         4
  CatA         5
  CatB         6
  </code></pre>
  
  <p>I hope I have been clear, this would really help me, so I'm looking forward to your solutions. :-) </p>
  
  <p>Thanks in advance! </p>