473,394 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Two Counts In One Query?

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
themselves.

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'
and
SELECT COUNT(*) AS UnRegisteredMembers FROM Contacts WHERE Membership='0'
but can I do this in one query?

THANKS!!
Jul 23 '05 #1
2 1362
Good Man wrote:
I can obviously get this result using two queries:
+
SELECT COUNT(*) AS RegisteredMembers FROM Contacts WHERE Membership='1'
and
SELECT COUNT(*) AS UnRegisteredMembers FROM Contacts WHERE Membership='0'


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

Regards,
Bill K.
Jul 23 '05 #2
Bill Karwin <bi**@karwin.com> wrote in
news:d8********@enews3.newsguy.com:
Good Man wrote:
I can obviously get this result using two queries:
+
SELECT COUNT(*) AS RegisteredMembers FROM Contacts WHERE
Membership='1' and
SELECT COUNT(*) AS UnRegisteredMembers FROM Contacts WHERE
Membership='0'


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


Thank you Bill.

I can't wait to sit down with a good SQL book this summer!
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: WertmanTheMad | last post by:
Ive been playing with this for a few days and thought I might thow it out for seggestions. I have Several Queries that need counts returned The Queries are Mutually Exclusive meaning whatever...
2
by: jcabc | last post by:
The row counts I am getting from SQL Enterprise Manager and Query Analyzer are different. When I double click a table in Enterprise Manager it gives me a row count of say 1000. However, when I...
1
by: Randy K | last post by:
I have a table with some 35000 records and I need some help sorting it out. The goal is to get counts of failures modes oraganized by serial number. the table is set up roughly like this. s/n ...
1
by: El | last post by:
I have 5 different fields setup on my report to be =Count(), etc. How do I go about adding the 5 counts together to get one total? I do not want the data that are in my fields for this report. I...
1
by: richforsandy | last post by:
I am working with a two field table of 144,020 rows. The PERSONID field is the FK and the ADDRESSID is the PK. FK is a number type, PK is autonumber. PERSONID represents employees,...
8
by: Tetelestai | last post by:
I would like three counts in one query based on differing criteria. Each count is counting the same items. The difference between the items being counted is the characteristics (eg like to short). ...
3
by: Bill Hutchison | last post by:
I have a query that returns different results (3508 rows for snapshot, 6288 for dynaset) and that is the only thing I change to get the different results. When I try to make a table from the...
9
by: ncyankeefan | last post by:
I am trying to get the number of specific alerts for each month of the year. I would like to get these counts in one query or subquery. There is a date field in table so I can specifically get the...
2
by: Superfreak31 | last post by:
Hello All, I need help with a SQL Query. I have a table with a StateId and PartNumber. I'll be joining some tables to get the state name from the StateId and Part Description from the Part...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.