Skip to content
Advertisement

How to join two total tables using sql?

For a university work we have two tables in sql:

table1:

table2:

I need to join the two tables by adding the total number of people in each city. So I tried to do:

However, if a city A appears in table 1 and does not appear in table 2 this would not work. The same would happen if a City B appears in table 2 and does not appear in table 1. How can I generalize these situations?

Desired output:

Advertisement

Answer

We can try to use UNION ALL with SUM instead of JOIN

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement