Question
SQL Union
I have a table by city, and population. I want to combine the
populations of two cities into one. For example, the city of Ojai
contains 10 people and the city of Santa Barbara contains 100
people. So for my output, I want to display the city as Santa
Barbara and the population as 110
My query is something like this :
select sum(population), 'Santa Barbara' as city
from
(
select population from table where city='Ojai'
UNION
select populatoin from table where city='Santa Barbara'
)
It is giving me the population of the first record it finds, instead of both records.
Is using UNION not the right way to do it ?
I am going to try QofQ next.
My query is something like this :
select sum(population), 'Santa Barbara' as city
from
(
select population from table where city='Ojai'
UNION
select populatoin from table where city='Santa Barbara'
)
It is giving me the population of the first record it finds, instead of both records.
Is using UNION not the right way to do it ?
I am going to try QofQ next.