MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SQL query to get the addition of two tables records count

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Wed Jul 27, 2005 4:48 am    Post subject: SQL query to get the addition of two tables records count Reply with quote

I have a table A with 20 records and i get the information by giving the query SELECT COUNT(*) FROM A,Similarly i have a table B with 80 records and i get the information by giving the query SELECT COUNT(*) FROM B.Can i have a query to get the addition of the count of the records from two tables as 100 records (addition of A + B ) ?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Jul 27, 2005 6:04 am    Post subject: Reply with quote

shekar123,

The following SQL will give you the desired results.

Code:

SELECT SUM(A.CNT)               
  FROM (SELECT COUNT(*) AS CNT 
          FROM TABLE1       
         UNION ALL             
        SELECT COUNT(*) AS CNT 
          FROM TABLE2) A     
 ;   


Hope this helps...

Cheers

kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Thu Jul 28, 2005 1:02 am    Post subject: Query for counting records from two tables Reply with quote

Hai Kolusu,

You are really great.The query did run fine and the logic used for the query is excellent.Thanks.


Shekar123
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group