I have 2 tables: incomes & outgo both containing information about transactions. I'd like to run a report to show the overall flow of money based on the totals in the tables, I currently do this manually by using the following queries:
1) SELECT amount, SUM(amount) AS intotal FROM incomes
2) SELECT amount, SUM(amount) AS outtotal FROM outgo
as an example, lets say intotal is 500 and outtotal is 300
I'd like a single query that gets both summaries and subtracts the outtotal amount from the intotal amount with a result of 200 in this case. can anyone point me in the right direction or help me with syntax?
SELECT SUM(amount) FROM (SELECT amount FROM incomes UNION SELECT amount FROM outgo) x