'How to count duplicates in a row PHP MYSQL

I have a usage database that i use to store some info whenever a user logs in.

So for each login the following is stored

  • rid (auto integer)
  • id (auto integer from the users database where the users details are stored login, contact details ect.)
  • username
  • password
  • date (y-m-d)

Is there a way to count the number of times that a duplicate id appears in the database and ORDER by DESC.

What I want is to tell who is the most active user by counting how many times the same id appears in the database.



Solution 1:[1]

SELECT id ,COUNT(*) 
FROM usageTable
GROUP BY id 
ORDER BY COUNT(*) DESC;

This will display a list:

id | COUNT(*)

10 | 203
2 | 100
5 | 83

Solution 2:[2]

mysql -> SELECT count(rid) FROM `tbl` ORDER BY rid DESC GROUP BY id

It will show you the number of activities for each id

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jentel