I have a table called tbl_users
A broken down version of it for this task
id | username | ref
I am trying to count the ref column for most entries and order by most to least.
This column displays users. So if there are 10 rows with “User 1” in the ref column it would return User 1 10.
How can I put this together?
EDIT.
I have put together the following query (using the 5 answers, thanks).
Is throwing up an error, saying the query isn’t valid basically.
$q = "SELECT ref, count(ref) as total_count FROM ".TBL_USERS." WHERE ref != 'NONE' GROUP BY ref ORDER BY total_count DESC";
Any ideas why?
ALL FIXED!!
edit:
Hmm. You have ‘user 1’ in the ref column, and want to count that. check.
Something like this should work?