When I run the below query:
select SUM(t1.total_amount) as one, SUM(t2.total_amount) as two
from table1 t1, table2 t2;
I get these results:
ONE TWO
2000 3000
But when I run this query:
select SUM(t1.total_amount) as one table1 t1;
I get this result:
ONE
50
It looks like the result from the first query is incorrect. Can anybody point me to the right direction?
When doing this:
you’re actually cross joining both tables, resulting in a cartesian product (every row in t1 is combined with every row in t2).
You’re probably missing a JOIN condition:
EDIT:
based on your comment, it looks like you want a union of these two separate queries
select ‘t1’, sum(total_amount) from t1
union
select ‘t2’, sum(total_amount) from t2
This will show the sums in two rows instead of columns, but it’s the easiest way AFAIK.