Click here to Skip to main content
14,982,875 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
tb1
Name Salary
Bob 1000
Tom 2000
John 3000
Winson 4000

tb2
Name Bonus
Bob 100
Tom 200


I would like to get the following result
Name Total
Bob 1100
Tom 2200
John 3000
Winson 4000


Please suggest how to resolve it

What I have tried:

SELEC tb1.Name, SUM(tb1.Salary + tb2.Bonus) Total From tb1, tb2 WHERE tb1.Name = tb2.Name group by tb1.Name order by Total
Posted
Updated 6-Oct-17 0:12am

1 solution

Use a JOIN:
SELECT t1.Name, COALESCE(t1.Salary + t2.Bonus, t1.Salary, t2.Bonus) AS Total FROM tb1 t1
LEFT JOIN tb2 t2 ON t1.Name = t2.Name 
   

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