Question: I read some topics about this but I'm not very good with sql. I have 10 tables with these fields:

* value
* type
* date

I want to sum all the value fileds together when they have a specific type. I was trying to do something like this, but it's not working.

```
select sum(tab1.value) + sum(tab2.value)
from tab1, tab2
where tab1.type = tab2.type = 'box'

```

I guess I could do many simple queries like these and then sum all the results

```
select sum(value) from tab1 where type='box'
select sum(value) from tab2 where type='box'

```

but I wonder if I can do one single query

thanks

Answer: 
Having multiple tables with the same structure is usually a sign of poor database design.

I would suggest that you use your last approach, but put the subqueries in the `from` clause and then add the results in the `select`:

```
select t1.value + t2.value + . . 
from (select sum(value) as value from tab1 where type='box') t1 cross join
     (select sum(value) as value from tab2 where type='box') t2 cross join
     . . .

```

Alternatively, you could `union all` them together in the `from` clause and then take the sum:

```
select sum(value)
from ((select sum(value) as value from tab1 where type='box') union all
      (select sum(value) as value from tab2 where type='box') union all
      . . .
     ) t;

```
If the tables are not linked via FK/PK you can use multiple sub-queries:

```
SELECT (SELECT SUM(tab1.value) FROM tab1 WHERE type='box') as Tab1Sum, 
       (SELECT SUM(tab2.value) FROM tab2 WHERE type='box') as Tab2Sum -- and so on...

```

This yields a single record where each column is the sum of each table.