0

Hi,

SQL below returns 1, 2, 3 in three rows. I want to see only 3 because there are total 3 records.

How can I solve this problem.

Thanks

SELECT COUNT(*) as totalProduct
                FROM customers
                INNER JOIN uploads ON customers.id = uploads.fk_id
                GROUP BY name
3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by veledrom
0

No, in that case it returns 7 because it is a 1 to n relationship. therefore, one customer has more than one uploads.

Can I not do it without adding this bit?

ORDER BY COUNT(*) DESC
                LIMIT 1
0
SELECT COUNT(*) as totalProduct               
 FROM customers                
INNER JOIN uploads ON customers.id = uploads.fk_id                
where name='MyRequiredName'
GROUP BY name
0

If you want to count that how many customers had uploaded then use the following query

SELECT COUNT(DISTINCT fk_id) FROM uploads
0

I decided to add bit below because there is another JOIN tehere. It is becoming a bit complex now. Anyway, thanks for your helps guys.

ORDER BY COUNT(*) DESC                LIMIT 1
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.