I have an sql query which calculates the number of distinct fileIds in a table. Given below is the query,
SELECT DISTINCT `fileId` AS FileId, Count( FileId ) AS NumberOfTags
FROM `Tag`
GROUP BY `fileId`
ORDER BY NumberOfTags DESC
The output of this query is given below,
FileId. NumberOfTags
1 500
2 500
3 550
4 550
5 550
I need to get the count of number of Files coming under each NumberOfTag value. Sample output should be something similar to this
NumberOfTags Number of Files
500 2
550 3
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
ERROR 1206 (HY000): The total number of locks exceeds the lock table size
Can someone please tell me how to create a nested query to do this task.
Thanks in advance.