How to Have Multiple Counts in MySQL

To do multiple counts in one query in MySQL, you can combine COUNT() with IF():

SELECT
  COUNT(1), -- Count all users
  COUNT(IF(gender='male', 1, 0)), -- Count male users
  COUNT(IF(beta=true, 1, 0)) -- Count beta users
  COUNT(IF(active=true AND beta = false, 1, 0)) -- Count active non-beta users
FROM users;
database icon
Better SQL for the people
Get more done with PopSQL and MySQL