Select count distinct columnname as cnt from tablename
I have a table called 'users' which has a column name 'gender' whose values are 'male' and 'female for all affected rows.
I want a row->count() of all distinct 'male' values and all distinct 'female' values.
$sql = "SELECT gender FROM users"; $namequery = $db->prepare( $sql );
How about this (and this is just general SQL syntax):
SELECT COUNT(Name) [Count], gender FROM (SELECT DISTINCT (name) [Name], gender FROM users) GROUP BY gender