Sagar
Sagar

Reputation: 7605

How to get combined output from two or more than two queries?

I have one table ABC. I am using queries

select count(*) from ABC where COLA=123; //output is 3

select count(*) from ABC WHERE COLA=321; //output is 6

I want both output combined like

| someColumnName |
|    3           |
|    6           |

Is there any way to frame query so that I can achieve this?

Upvotes: 0

Views: 50

Answers (3)

Trinimon
Trinimon

Reputation: 13967

Just another option:

SELECT count(*) as SomeColumnName
FROM ABC 
WHERE COLA = 123 
   OR COLA = 321
GROUP BY COlA;

:)

Upvotes: 0

Fabienne B.
Fabienne B.

Reputation: 363

Use UNION between your two queries:

select count(*) as someColumnName  from ABC where COLA=123
union
select count(*) from ABC WHERE COLA=321;

Upvotes: 5

xQbert
xQbert

Reputation: 35343

use a group by and where clause.

SELECT count(*) as SomeColumnName
FROM ABC 
WHERE COLA in (123,321)
GROUP BY ColA

Upvotes: 4

Related Questions