3

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?

1 Answer 1

5
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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.