All Forums General
chandrareddy321 4 posts Joined 08/13
12 Sep 2013
Combine two queries into single

Is there any way to combine below two queries into single query:

 

select count(*) from Employee;

select SUM(CURRENTPERM) from DBC.TABLESIZE where TABLENAME='Employee'  and DATABASENAME='test';

 

Thanks for your help!

M.Saeed Khurram 544 posts Joined 09/12
13 Sep 2013

Hi,
Below is one of the way you can combine the output of these two queries:

SELECT ROW_COUNTS, SUM(CURRENTPERM) FROM DBC.TABLESIZE,
(
SELECT COUNT(*) AS ROW_COUNTS FROM Employee
) DRV_EMP
WHERE TABLENAME='Employee'  AND DATABASENAME='Employee_Sales';

 

Khurram

Qaisar Kiani 337 posts Joined 11/05
13 Sep 2013

You didn't mention in which format you need the resultset.... Single row with two columns or Two rows against one column.
If you need two columns then the query mentioned by Khurram will work
And if you need the result of both queries in single column format then you can use UNION clause in between the two queries

chandrareddy321 4 posts Joined 08/13
13 Sep 2013

it's working fine thanks a lot Khurram & Abkiani.

You must sign in to leave a comment.