I'd like to do an SQL query to get a sum number, but i don't know how to construct this query.
select count(*) from table1 where commom_fk in (1234);
select count(*) from table2 where commom_fk in (1234);
select count(*) from table3 where commom_fk in (1234);
select count(*) from table4 where commom_fk in (1234);
select count(*) from table5 where commom_fk in (1234);
I wanna to sum these results in just one query, is that a way to do this?
Thank you all. -----*
This was answered. But if i wanna to do this with more than one common_fk?
SELECT
( SELECT ...)
+ ( SELECT ...)
+ ( SELECT ...)
+ ( SELECT ...)
+ ( SELECT ...)
AS sumAll
or to have all 5 results:
SELECT
( SELECT ...) AS sum1
, ( SELECT ...) AS sum2
, ( SELECT ...) AS sum3
, ( SELECT ...) AS sum4
, ( SELECT ...) AS sum5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With