I have created my SQL Fiddle on the following URL for testing and building my query:
http://sqlfiddle.com/#!2/5415d/3
Consider the following structure of my table:
TABLE1 +-------------------------+ | Username | Event ID | +-------------------------+ | Jhon | ABC | | Nick | ABC | | Hen | ABC | | Jhon | DEF | | Jhon | ABC | +-------------------------+
The Query I am trying to write is that when user want to see the eventsID related to user Jhon then as you can see that there are various similar id against jhon in the above table and some are not so query should return something like the following output in Descending order as per Count (Event_ID):
+-----------------------------------------------+ | Username | Event ID | Count (Event_ID) | +-----------------------------------------------+ | Jhon | ABC | 3 | | Jhon | DEF | 1 | +-----------------------------------------------+
Kindly let me know how can I write such query.
Thanks,
SQLFiddle demo