user5951209 - 8 months ago 46

SQL Question

I'm creating a cinema database and I'm stuck on a certain point in my insert script.

Im creating tickets and I need a totalprice, this price is the sum of two values that I search using several subquerys.

Here are the two querys

`Select toelage`

from klanttype

where type =

(

Select type

from klant

where klantnr = (

Select klantId

from Verkoop

where verkoopId = 2512

)

);

select toelage

from zetelzone

where zone = (

select zone

from zetel

where zetelnr = 130

);

I'm now stuck on adding the two values together to create one number to insert into the Ticket table.

Answer

you can sum up both queries via a union all.

```
select sum(toelage)
from (
Select toelage
from klanttype
where type =
(
Select type
from klant
where klantnr = (
Select klantId
from Verkoop
where verkoopId = 2512
)
)
UNION ALL
select toelage
from zetelzone
where zone = (
select zone
from zetel
where zetelnr = 130
)
);
```

Source (Stackoverflow)