Reputation: 33
I need to count the number of records returned from a MySQL query.
SELECT
COUNT(sa.facility_hmis) AS deployed
FROM
facility_service_area sa
GROUP BY sa.facility_hmis
this will give me lets say 6 rows as the result, but i need it to give me a single row with just the number counted rows i.e 6
Upvotes: 0
Views: 40
Reputation: 12953
Use distinct
SELECT COUNT(distinct facility_hmis) AS deployed FROM facility_service_area
Upvotes: 3
Reputation: 254926
If all you need is to count number of distinct facility_hmis
you can do that explicitly, without counting of anything else:
SELECT COUNT(DISTINCT facility_hmis) FROM facility_service_area
Upvotes: 3
Reputation: 1536
Wrap the query in another count()
SELECT COUNT(1) from (
SELECT COUNT(sa.facility_hmis) AS deployed FROM facility_service_area sa GROUP BY sa.facility_hmis
)
Upvotes: 1