Two Counts In One Query?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi there

I'm wrapping up my first *really* big, complex web application, and in
doing so, I realize that my next tast will be reading some SQL books and
learning how to improve my querying.  I really didn't know that i could
work math equations, comparisons, and if clauses right in the statements

Anyways, I digress.  I'm looking for a way to query the following... I have
a database full of people, where the Membership field is either a '1' or
'0'.  I'd like to get the total counts for both situations in one query.  
Something that will give me:

RegisteredMembers | 332
UnregisteredMember | 543

I can obviously get this result using two queries:
SELECT COUNT(*) AS RegisteredMembers FROM Contacts WHERE Membership='1'
SELECT COUNT(*) AS UnRegisteredMembers FROM Contacts WHERE Membership='0'

but can I do this in one query?


Re: Two Counts In One Query?

Good Man wrote:
Quoted text here. Click to load it

SELECT Membership, COUNT(*)
FROM UnRegisteredMembers
GROUP BY Membership

Bill K.

Re: Two Counts In One Query?

Quoted text here. Click to load it

Thank you Bill.

I can't wait to sit down with a good SQL book this summer!

Site Timeline