title: Need a nested SQL query which takes the count from the first query and calculate a new count
body: <p>I have an sql query which calculates the number of distinct fileIds in a table. Given below is the query,</p>
  
  <pre><code>SELECT DISTINCT `fileId` AS FileId, Count( FileId ) AS NumberOfTags
  FROM `Tag`
  GROUP BY `fileId`
  ORDER BY NumberOfTags DESC
  </code></pre>
  
  <p>The output of this query is given below,</p>
  
  <pre><code> FileId. NumberOfTags
  
   1  500
  
   2 500
  
   3 550
  
   4 550
  
   5 550
  </code></pre>
  
  <p>I need to get the count of number of Files coming under each NumberOfTag value. Sample output should be something similar to this</p>
  
  <pre><code> NumberOfTags Number of Files
  
   500 2
  
   550 3
  </code></pre>
  
  <p>The results of the first query is pretty large, it has around 3 Million rows. I tried to create a table of the results of the first query but it also failed with an error </p>
  
  <pre><code>ERROR 1206 (HY000): The total number of locks exceeds the lock table size
  </code></pre>
  
  <p>Can someone please tell me how to create a nested query to do this task.</p>
  
  <p>Thanks in advance.</p>