我正在编写MySQL查询时出现问题。我想得到我的查询返回的行数,而不是实际返回行,然后使用mysql_num_rows等。
我的查询如下:
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
以下是返回的内容:
而我真正想要的只是这些行的计数,所以在这种情况下为3。
答案 0 :(得分:39)
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