PDA

View Full Version : SQL Query Question


TheMayhem
02-08-2006, 06:17 PM
I'm just wondering on an sql query let's say I have a userid column on a particular table and I want to see which userid is repeated the most throughout the table, what kind of mysql command would I need to enter to list in DESC order from the most entrees of a userid column to the list.

So if I had let's say 5 table entrees. 3 of them where for userid 2, one of them was for userid 1 and the other was for userid 3, It'd list

the three tables with userid 2 firstm then userid 1 then userid 2.

Then next question is how would I write a mysql_num_rows statement to just quickly fetch the total number of entrees by whoever has the largest entree number in a particular table which in this case would be userid 2 with 3 entrees.

Xenon
02-08-2006, 07:34 PM
SELECT COUNT(*) AS counter, userid
FROM table
GROUP BY userid
ORDER BY counter DESC

and add a limit 1, if you want just the top user ;)