[snip]
id | product
------------
0 | switch
1 | switch
2 | hub
3 | hub
4 | hub 
5 | wire
6 | wire
7 | wire
8 | wire
9 | wire
.
.
I`m looking for query which give me result as array:
0 - > count of 'switch'
1 - > count of 'hub'
2 - > count of 'wire'
[/snip]

SELECT COUNT(product), product FROM table GROUP BY product;

Now, this doesn't give you an array, but you can use this query to
populate an array in the programming language that you are using, such
as PHP...

$sql = "SELECT COUNT(`product`), `product` FROM `table` GROUP BY
`product`" ;
if(!($result = mysql_query($sql, $connection_string))){
   echo "MySQL Error: " . mysql_error() . "\n";
   exit();
}
$sqlArray = mysql_fetch_array($result); // returns a one row array, just
loop through to access all rows

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to