Using SELECT UNION and returning output of two columns from one table
oracle, select, sql, union
Solution
another way without using case:
select sum(males) as "Male Actors", sum(females) as "Female Actors"
from
(select count(actorGender) as Males, 0 as Females
from tblActor
where actorGender = 'm'
union all
select 0 as males, count(actorGender) as Females
from tblActor
where actorGender = 'f')
should result in
Male Actors Female Actors
----------- -------------
7 21
Problem
I am creating a query that counts the amount of male and female actors in my table. My current statement is as such: ``` Select COUNT(ActorGender) “Male Actors” from (tblActor ta WHERE ta.ActorGender in(‘m’) UNION Select COUNT(ActorGender) “Female Actors” from tblActor ta WHERE ta.ActorGender in(‘f’); ``` The output ends up being: ``` Male Actors ----------- 7 21 ``` I want the output to look like: ``` Male Actors Female Actors ----------- ------------- 7 21 ``` I am looking for an alternative to go about this without using the CASE WHEN or THEN clauses. Thanks in advance for the help as usual.