Here is a link to a very similar question, except in their example they only are concerned about one column, where I will be concerned about more than one. SQL Select most common values
Here is my problem:
I need to display an email addr, number of comments that user has left, and display the most common username associated with each email. I have already taken care of the first two steps; i.e. I have it displaying email along with number of comments. Now the client wants the most common username.
here is the query to get the the email and count of comments I mentioned above.
select comment_author_email, count(*) from wp_comments group by comment_author_email order by count(*) desc
Now I have the task of getting the most common username to display in the third column.
For example:
email | username | comment
------------------------------
1@test | one | blah..
1@test | ONE | blah..
1@test | one | blah..
2@test | TWO | blah..
2@test | TWO | blah..
3@test | tre | blah..
I would expect as output
email |numComments| mostCommonName
------------------------------------
1@test | 3 | one
2@test | 2 | TWO
3@test | 1 | tre