I have a table with columns
id date title
I want to get the list of total occurrences of each title per date. So for example get:
date title total
20 Apr - My Title A - 3
20 Apr - My Title B - 2
21 Apr - My Title A - 5
22 Apr - My Title B - 1
22 Apr - My Title C - 1
23 Apr - My Title A - 6
23 Apr - My Title B - 2
23 Apr - My Title C - 5
24 Apr - My Title C - 2
24 Apr - My Title D - 2
BUT I only want to get the records that have the most values, so from the example above, the total occurrences are:
A 14
B 5
C 8
D 2
If I would only want the top 2, then what I would expect is the first list but only filtering top titles:
20 Apr - My Title A - 3
21 Apr - My Title A - 5
22 Apr - My Title C - 1
23 Apr - My Title A - 6
23 Apr - My Title C - 5
24 Apr - My Title C - 2
My first approach is to do a subquery counting the top by title., and then filter where titles are in the list of most counts. But I wanted to know if there is a simpler way.