Combine two queries into single

General

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!

Tags (1)
3 REPLIES
Enthusiast

Re: Combine two queries into single

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
Enthusiast

Re: Combine two queries into single

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

Re: Combine two queries into single

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