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 );

Answers


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

Need Your Help

Sending a POST request from Cocoa to Tumblr

cocoa tumblr nsmutableurlrequest

This code snippet isn't working, I'm getting an "Authentication Failed." response from the server. Any ideas?