Darren Sweeney wrote:
>
> Hi
>
> I need to search one table for about twelve different items and return the number
> found for each one ... preferably in an array that I can simply call as e.g. $count[0],
> $count[1] etc. etc.
>
> At the moment I am doing:
>
> my $query = "select count(*) FROM items WHERE ( category like \"pc_digital_cameras\"
> )";
> my $sth = $dbh->prepare($query);
> my $rc = $sth->execute;
> $digcam = $sth->fetchrow;
> $sth->finish;
>
> my $query = "select count(*) FROM items WHERE ( category like \"pc_memory\" )";
> my $sth = $dbh->prepare($query);
> my $rc = $sth->execute;
> $mem = $sth->fetchrow;
> $sth->finish;
>
> I'm thinking there must be a more structured and organized way to do this rather than
> running 12 seperate queries.
>
Maybe you're looking for the GROUP BY syntax (multiple rows returned):
select category, count(*) FROM items GROUP BY category;
jim...