Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get number of rows returned in MySQL query

Tags:

mysql

I'm having some trouble with a MySQL query I'm writing. I'd like to get a count of the number of rows that my query is returning without actually returning the rows and then using mysql_num_rows or the like.

My query is as follows:

SELECT COUNT(l.product_number_language) as counts, l.id, l.product_number, l.language,    l.product_number_language
FROM bs_products_languages l
LEFT JOIN bs_products p ON (l.product_number_language = p.product_number)
WHERE l.product_number = 'C4164' 
AND l.active='Y'
AND p.active='Y'
GROUP BY l.language

The following is what is being returned: Screenshot

And what I really want is simply a count of these rows, so in this case 3.

like image 727
carbide20 Avatar asked Feb 21 '13 15:02

carbide20


1 Answers

Select count(*)
From
(
    SELECT COUNT(l.product_number_language) as counts, l.id, l.product_number, 
        l.language, l.product_number_language
    FROM bs_products_languages l
    LEFT JOIN bs_products p ON (l.product_number_language = p.product_number)
    WHERE l.product_number = 'C4164' 
    AND l.active='Y'
    AND p.active='Y'
    GROUP BY l.language
) as t
like image 188
Andy Refuerzo Avatar answered Oct 08 '22 01:10

Andy Refuerzo