user1573319
user1573319

Reputation: 69

A better way to improve this query in mysql

I want to get sum of different columns from different tables, I have done something like this below, I think there is much better way that this in mysql

select 
(select sum(sal) from budget_tp) as sal_tp, 
(select sum(sal) from budget_fos_veri) as sal_veri,
(select sum(sal) from budget_fos_picks)as sal_pick,
(select sum(sal) from budget_bpo_other)as sal_bpo;

Upvotes: 1

Views: 120

Answers (1)

Najzero
Najzero

Reputation: 3202

Depending on the amount "summed" up, you could use something like nightly-jobs (selects) that fill cache-tables - since budget numbers don't need to be 100% live values (anyone saying SAP HANA now, gets a high five to the face with a chair)

For the pure performance your select statement is as good as it gets.

Edit: this was a purely simplyfied approach. You could also do nightly-jobs for the huge datasets and only add the difference added to your tables since the last job summing up.

Upvotes: 1

Related Questions