So on my site in my members table named 'members' there is a row in it called 'usertype'. Now that value of that can be 1, 2, 3, or 4. I want to find a fast way of finding out the number of rows with each number and seeing which two are the lowest. The current way I am doing it is counting the number of rows of each type. Then using 4 if statements to decide which is the lowest number. Then another 4 to see which is the second lowest, and some more to make sure those two numbers are not the same. There must be a faster way of doing this.
The quickest and easiest way would be to do it all in the database, in one script.
Without having the ability to test, it should be something like
SELECT usertype, COUNT(usertype) AS typecount FROM members GROUP BY usertype ORDER BY typecount