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.
9 3075
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;
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.
PEB 1,418
Recognized Expert Top Contributor
Hi Ericka,
You can try the following: -
-
Select
-
"Employee_Table" as Table_Name,
-
Count(*) As Record_Total
-
-
From Employer_table
-
-
UNION ALL
-
-
Select
-
"Worker_Table" as Table_Name
-
-
Count(*) As Record_Total
-
-
From Worker_Table
-
-
UNION ALL
-
-
Select
-
"All" as Table_Name
-
-
nz(DCount("*","Worker_Table",""))+nz(DCount("*","Employer_table","")) As Record_Total;
-
-
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.
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 .
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
PEB 1,418
Recognized Expert Top Contributor
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
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;
Thank you so much for exchanging knowledge with others.The query is working.
Regards,
Ericka
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:
|
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' ,
|
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...
|
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:
|
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...
| |
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |