473,756 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help for getting grand total of counting records from two tables.

7 New Member
I used the following query to count the number of records from each table.

Select
"Employee_Table " as Table_Name,
Count(*) As Record_Total

From Employer_table

UNION ALL

Select
"Worker_Tab le" as Table_Name

Count(*) As Record_Total

From Worker_Table;

Can anyone help me to add the grand total(SUM) of all the records from both the tables.
Oct 1 '06 #1
9 3075
Tanis
143 New Member
Why not have seperate queries to return the count of both seperate tables, then have a third query as your sum?

SELECT Count(Employee_ Table.Employee) AS CountOfEmployee
FROM Employee_Table;

SELECT Count(Worker_Ta ble.Worker) AS CountOfWorker
FROM Worker_Table;

SELECT [CountOfEmployee]+[CountOfWorker] AS SumTotal
FROM qryEmployeeCoun t, qryWorkerCount
GROUP BY qryEmployeeCoun t.CountOfEmploy ee, qryWorkerCount. CountOfWorker;
Oct 2 '06 #2
Ericka
7 New Member
Thanks for your reply. But I would like to know the SUM of records from both tables in the same query.

Please help me out.
Oct 2 '06 #3
PEB
1,418 Recognized Expert Top Contributor
Hi Ericka,

You can try the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Select
  3. "Employee_Table" as Table_Name,
  4. Count(*) As Record_Total
  5.  
  6. From Employer_table
  7.  
  8. UNION ALL
  9.  
  10. Select
  11. "Worker_Table" as Table_Name
  12.  
  13. Count(*) As Record_Total
  14.  
  15. From Worker_Table
  16.  
  17. UNION ALL
  18.  
  19. Select
  20. "All" as Table_Name
  21.  
  22. nz(DCount("*","Worker_Table",""))+nz(DCount("*","Employer_table","")) As Record_Total;
  23.  
  24.  
Best regards

PEB

:)

I used the following query to count the number of records from each table.

Select
"Employee_Table " as Table_Name,
Count(*) As Record_Total

From Employer_table

UNION ALL

Select
"Worker_Tab le" as Table_Name

Count(*) As Record_Total

From Worker_Table;

Can anyone help me to add the grand total(SUM) of all the records from both the tables.
Oct 2 '06 #4
Ericka
7 New Member
Thank you so much for your reply with code. When I used the code which you provided still I am getting error. Can you help me if possible .
Oct 2 '06 #5
Ericka
7 New Member
Thank you so much for your reply with code. When I used the code I am getting error ."Query input must contain at least one table or Query".Can you help me if possible
Oct 2 '06 #6
PEB
1,418 Recognized Expert Top Contributor
Is it working?
Oct 7 '06 #7
Ericka
7 New Member
Sorry for not responding immediately. I tried the way thatyou suggested. Although the query is giving the Grand total of the records, it is looping and giving the Grand total so many times.I dont know how to avoid looping.If you know any other way please let me know.

Thanks,
Ericka
Oct 7 '06 #8
PEB
1,418 Recognized Expert Top Contributor
So yeah it's possible

However try:

Select
"Employee_Table " as Table_Name,
Count(*) As Record_Total

From Employer_table

UNION ALL

Select
"Worker_Tab le" as Table_Name

Count(*) As Record_Total

From Worker_Table

UNION ALL

Select DISTINCT
"All" as Table_Name

Count(*)+nz(DCo unt("*","Employ er_table","")) As Record_Total
From Worker_Table;
Oct 7 '06 #9
Ericka
7 New Member
Thank you so much for exchanging knowledge with others.The query is working.

Regards,

Ericka
Oct 10 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1369
by: sah | last post by:
Can someone please help me write a stored procedure? I run a query (see below) for 50 tables and for every day of the month. I would like a SP which can provide data with results as follows: Srv_Name, DB_Name, Table_Name, Date_Of_Records, Total_Records, Min_SerNumber, Max_SerNumber, Should_Be_Total_Records, Missing_Records The query I currently run for each table and each single data is below:
4
1879
by: sah | last post by:
I need some help with the following query: DECLARE @SRV VARCHAR(20), @date smalldatetime SET @SRV = (select @@servername) SET @date = '20040901' select Srv_Name = @SRV, DB_Name = 'DB_NAME', Table_Name = 'Info_Table', Date_of_Records = @date, count(*) AS 'Actual Total' ,
1
4803
by: Dalan | last post by:
I have tried both methods of using DSum and creating a Function to address summing some number columns, but to no avail. Since this has been a popular topic over the years, I'm sure I'll receive some guidance. This is related to Access 97 and involves my redoing a miscellaneous purchase and sales form. A main form (frmMain) is used that contains summary information of the item. I incorporated two continuous subforms (sfrmPurchases) and...
3
3250
by: CSDunn | last post by:
Hello, I have 14 fields on a report that hold integer values. The field names use the following naming convention: T1Number, T2Number ....T14Number. I need to get a 'sub total' of all fields as follows: =Sum() ... =Sum() Then I need to get an average of all fields as follows:
17
1971
by: EkteGjetost | last post by:
This is definitely not the smart thing to do as far as my learning goes, but desperate situations call for desperate measures. The final lab for my introduction to C programming class is due tomorrow. I was on vacation when we went over how to read files, so basically my only resources are the book, the course notes, and the examples. Unfortunately for me, none of them are usefull at all, so pretty much i don't have a clue as to what i...
4
6016
by: Sean Shanny | last post by:
To all, Running into an out of memory error on our data warehouse server. This occurs only with our data from the 'September' section of a large fact table. The exact same query running over data from August or any prior month for that matter works fine which is why this is so weird. Note that June 2004 through today is stored in the same f_pageviews table. Nothing has changed on the server in the last couple of months. I upgraded...
7
1835
lee123
by: lee123 | last post by:
hey all, i have made a order form with all the works. in vb 6 and in this form i have been trying to get a total of the items that a customer would have ordered. to make things make sense i have in my order form ( qty, product,unit price, and a total) there are 12 rows of these text boxes (1-44) i believe, any way on the bottom of the order form there is a (subtotal,salestax,final total.) now the question is.....(and it probably a simple one i...
2
1487
by: cephal0n | last post by:
Hi All! First of I apologize for my previews post needing help on union select and not providing so more explanation, but thank you very much for your opinion and sugestion. I have thought about my problem and try to find a solution. I now have few answres and would like to ask for your expertise on how I handled my sql. I made an sql code, I used sql specific by creating query > new > design view> close the Show Table > right click> click...
2
3040
by: Bytesmiths | last post by:
I'm using GROUP BY to come up with totals for some items, but would like to either have a grand total at the bottom, or a running total field. I tried to use a variable as I found in several places on the web: SELECT @total := total + value AS `Running Total` but what I'm totalling is an aggregate, and it doesn't seem to work. I tried to explore some options dev.mysql.com, but again, my field seems to be too complex. More specifically,...
0
9456
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10034
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9872
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9843
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.