title: Using max function on the resultset of count
body: <pre><code>==========================  
      uid     |     tid
  ==========================
       1      |      0
       1      |      1
       1      |      2
       2      |      1
       2      |      2
       3      |      2
       4      |      3
       4      |      0
       4      |      4
  </code></pre>
  
  <p>etc..</p>
  
  <p>This is the "join-table" in my many-to-may relationship. What I want to do is to count 'tid' (grouped). Then I want to find the highest count of 'tid'. When I have done that I want to use that 'tid' to join it with the lookup-table (9 rows with the tid as primary and description of that category)</p>
  
  <p>What I have written so far is:</p>
  
  <pre><code>select tid, max(count) from (select tid, count(tid) as count from klb_log_food_maps group by tid);
  </code></pre>
  
  <p>The count returned is correct however the 'tid' is not correct, seems like it is the last tid in that table.</p>