angie angie - 5 months ago 12
MySQL Question

Ho to dispaly the three biggest numbers of one of the columns of a database table?

I have to write a

php
script to find the three biggest numbers of a column in a database table. This is my code so far, but it doesn't work .

<?php
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("pool");

$res1=mysql_query("SELECT * FROM buy ORDER BY value LIMIT 3 ");

while($r1=mysql_fetch_array($res1)){
echo $r1['value'];
}
?>

Answer

Try this

SELECT * FROM `buy` ORDER BY `value` DESC LIMIT 3 
Comments