Click here to Skip to main content
15,667,231 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello every one Happy holiday to all,

I am writing a project for my organisation on monthly aggregate database i have a table that i split into three table i want to sum all the rows to form a Grand Total which i am to display on the dashboard, sample of it is as below :

select * from tbl_htc1 a join tbl_htc2 b on a.years = b.years join tbl_htc3 c on b.years = c.years
where a.years = b.years and b.years = c.years

above the SQL statement I used to join the three tables, i need all the rows data's to be sum together and return the grand Total this i will display on the application dashboard.

any help will be appreciated as the is so urgent for me

thank you all and God bless

above is the sql statement to join the three table together, but i want to sum all the rows to get the Total sum of all the rows.
Updated 22-Dec-15 15:15pm
debashishPaul 22-Dec-15 21:16pm    
Which field do you want to sum up?

1 solution

The easiest way would be to union the tables and sum the result


Select Sum(a) from (
Select Sum(field) as a from tableA
union all
Select Sum(field) as a from tableb
union all
Select sum(field) as a from tablec)as T

From each of the select statement you can add whatever filter you need.

See SQL Union[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900