sql - Combining output of two or more select statement -


how combine output of 2 or more select statements, have multiple tables having data need fetch them write multiple select query. want combine result of queries need ? want output be:

t1.qty,t2.qty,t3.qty  

one option be:

select (select sum(qty) table1 ...),        (select sum(qty) table2 ...),        (select sum(qty) table3 ...) 

another joining, provided there link:

select *    (select id,sum(qty) table1 group id) t1        join (select id,sum(qty) table2 group id) t2            on t1.id = t2.id        join (select id,sum(qty) table3 group id) t3            on t1.id = t3.id 

the above options display results in 1 row.

you may need union combine rows:

select qty table1 union select qty table2 union select qty table3 

much more options if define more specific needs


Comments

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

vb.net - Alternative to the T-SQL AS keyword -