I need help with writing a query (mySQL) to
- Total number of users in a project, and
- Number of users in that project that have been "disabled"
Now, I can do it separately, like this:
SELECT count(users) FROM t1 WHERE project = 3
SELECT count(users) FROM t1 WHERE project = 3 AND status = "disabled"
But there’s gotta be a simple way of combining the two in one query…
You can use UNION:
Other solution are subqueries:
Anyway, the truth about those solutions is that two separate queries will do just fine. Only on very large systems this would matter. When we look at database performance, those two will be slower than two separate queries. The only reason we would want to do that is overhead from connection to the database.