Abel Pule Chilungu Abel Pule Chilungu - 1 month ago 17
MySQL Question

counting COUNT(*) results in MySQL

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

Answer

Use distinct

SELECT COUNT(distinct facility_hmis) AS deployed FROM facility_service_area
Comments