473,387 Members | 1,495 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,387 software developers and data experts.

Sum of Two Union Queries

Hi I have the following union query that retrieves two counts. Can I
sum them up within this query, like wrap this in a sum function
somehow to get the total count? Or is there a better way to do this.
Please help. Using SQL 2000.

select count(user_id) from table1

UNION

select count(user_id) from table2
Jul 20 '05 #1
2 50146
Brent,

First, I'm guessing you don't really
mean UNION here. If you did, you would
get

----------
40

from your query if by chance each of table1
and table2 contained 40 rows each with non-null
user_id values.

Because you mention UNION, I'm not sure whether
you might want the total count of unique user_id
values from the two tables, or just the sum of
the counts.

If you want the latter, just the sum of the counts,
here is a possibility:

select
(select count(user_id) from table1)
+ (select count(user_id) from table2)
as totalCount

If you need to count user_id values only once when
they appear in both table1 and table2, you can do this:

select count(user_id)
from (
select user_id from table1
union
select user_id from table2
) T

-- Steve Kass
-- Drew University
-- Ref: 68959432-090F-4058-8185-BE7DA62CBE6A

Brent Wege wrote:
Hi I have the following union query that retrieves two counts. Can I
sum them up within this query, like wrap this in a sum function
somehow to get the total count? Or is there a better way to do this.
Please help. Using SQL 2000.

select count(user_id) from table1

UNION

select count(user_id) from table2


Jul 20 '05 #2
This helps a lot... thanks!

Steve Kass <sk***@drew.edu> wrote in message news:<eT******************@newsread2.news.atl.eart hlink.net>...
Brent,

First, I'm guessing you don't really
mean UNION here. If you did, you would
get

Jul 20 '05 #3

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

Similar topics

2
by: d2r2 | last post by:
Hi, I'm trying to run a nested (UNION) query against a MSAccessXP database (version 2002; build 10.6501.6714; SP3) In Access the SQL-statement executes just fine. When I run it in a asp-page I...
2
by: Fred Zuckerman | last post by:
I have a union query joining two other queries, each with 62 fields. Interestingly, when I open the query it has the correct number of 2850 records. But if I then set a filter (using filter by...
5
by: Alicia | last post by:
Hello everyone based on the data, I created a union query which produces this. SELECT ,,, 0 As ClosedCount FROM UNION SELECT ,, 0 AS OpenedCount, FROM ORDER BY , ;
1
by: Fl?vio | last post by:
Hey! Please help me... I'd like to know if there's a limit of tables that I can unite in a union query (maybe 16?). When I add more than 16 tables I'm getting an error message. Thank you in...
2
by: Aaron Haspel | last post by:
Greetings Access gurus. I have clients with Access databases in the field that I need to update -- new tables, new indices, new queries, the works. Since these clients may have only the Access...
3
by: Paul H | last post by:
I have been building access databases for a few years now and have never built a union or pass through query. What are these strange mythical beasts? What do they do? Paul
0
by: tdotsmiley | last post by:
Hi, I have multiple union queries that I have. These are from 4 different tables. Is there a way I can use the report feature so that it combines all of the queries into one file so that I can...
5
by: BillCo | last post by:
I've encountered a problem while using ADO to save query objects. Union queries created normally (via the interface) appear in adox catelog.procedures rather than catelog.views. This is reasonably...
2
by: MLH | last post by:
Consider having tblCorrespondence, then copying & pasting it to tblCorrespondence1 - such that they are identical. Then consider the following UNION SELECT statement... SELECT...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.