Does anyone know how can I add an integer from another table to the current selected table in SQL Server?
For example: I have 2 tables with the following information in each table
tableA:
id username point status country 1 alvin 1 1 U.S.A 2 alvin 1 1 U.S.A 3 amy 1 0 Australia
tableB:
id username point 1 amy 1 2 alvin 1 3 ken 1
How can I sum up the total points in tableA with also add in the sum points from tableB? I tried the following code, but seem is not working and error display:
SELECT username, (COUNT(distinct a.point) + (SELECT SUM(a.point)
FROM tableB b WHERE b.username = a.username) AS 'Points', status, country
FROM tableA
GROUP BY aco.username
And the output I expected will be:
username Points status country
alvin 3 1 U.S.A
amy 2 0 Australia