Getting multiple dynamic counts on a single column

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Getting multiple dynamic counts on a single column

Post by printf »

Is there some method to return a single row with multiple COUNTS on single column based on different values matching that column?
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

Since the counts in the field clause are tied to a single where clause, you will need to do this with subqueries like

Code: Select all

SELECT
( SELECT COUNT(*) FROM tbl WHERE something=something) as myFirstCount,
( SELECT COUNT(*) FROM tbl WHERE something=somethingelse) as mySecondCount
Post Reply