0

I have 3 tables and I want to know with one query sum of row's number in 3 tables

I tried 2 different queries but it they give only the number of rows each table and I c'ant read with,

     return int.Parse(cmd.ExecuteScalar().ToString());

the sum of rows of 3 tables.

I must read by reader and get the sum

Here are 2 queries I used:

    SELECT  (
        SELECT COUNT(*)
        FROM   prodbiscuit WHERE status =2
        ) AS count1,
        (
        SELECT COUNT(*)
        FROM   prodganache WHERE status =2
        ) AS count1,
        (
        SELECT COUNT(*)
        FROM   prodmacaron
        ) AS count1
        FROM   dual

And the other query which give the same result:

       SELECT COUNT(DISTINCT nom) as rows FROM prodbiscuit WHERE status=2 

       UNION SELECT COUNT(DISTINCT nom) AS rows FROM prodganache WHERE status=2  

       UNION SELECT COUNT(DISTINCT nom) AS rows FROM prodmacaron

How to get real sum of rows of tree tables with one query?

Should I use absolutely reader ?

2 Answers 2

1

http://searchoracle.techtarget.com/answer/Sum-of-two-table-row-counts-as-one-answer

 select ( select count(DISTINCT nom) from prodbiscuit WHERE status =2 )
 + ( select count(DISTINCT nom) from prodganache WHERE status =2 ) 
 + ( select count(DISTINCT nom) from prodmacaron) 
      as total_rows

Finally I've found it at given link

0
0

I would create a variable then add each one to the variable. When its done, the variable would have the result. I'm coming up with this off the top of my head. It sounded viable.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.