|
Posted by a on 11/03/11 11:16
Irlan agous wrote:
> Hello i get the information out of one field named persid. Now i get a list
> of all the persid's like 2,2,3,4,4,4,5. I want to select the maximun
> existing values, the second maximum etc. For example in this care number 4
> had the highest rank(with 3 times), second is 2 (with 2 times) etc. But how
> can i save distinct numbers and its amount to a variable? becouse then im
> able to check which one is the maximum etc, thanks for the help
>
> $query = "select persid from reactie";
> $result = mysql_query("SELECT persid FROM reactie");
>
> while ($array = mysql_fetch_array($result);){
> echo "The name is " . $array[persid];
> }
>
> Irlan
>
>
SELECT persid, count( persid ) AS cnt
FROM reactie
GROUP BY persid
ORDER BY cnt DESC
Cheers,
Nikolaj
Navigation:
[Reply to this message]
|