I am trying to create one table out of the following 2 tables and running into a lot of problems.
Table 1 has the following:
Month,
Salesperson_Assigned,
Product1_Revenue
Table 2 has the following (different product):
Month,
Salesperson_Assigned,
Product2_Revenue
The problem is that while all the months are the same, there are some salespeople in Table 1 not in Table 2, and vice versa. Obviously the revenue is different. I want to join the tables to look like Month, Salesperson, Product1_revenue + Product2_revenue.
Here's the query I'm using:
SELECT
Table1.month,
Table1.salesperson_assigned,
sum(Table1.revenue + Table2.revenue)
FROM
Table1
INNER JOIN Table 2 ON (Table1.month = Table2.month) AND (Table1.salesperson_assigned = Table2.salesperson_assigned)
The output isn't correct even though I confirmed the revenue values in each individual table are correct. The output seems to be making up additional values for the salespeople who appear in only 1 table for the field that should be null.
Anyone had any advice for how to join the 2 tables properly so it acts similar to a pivot table, adding the unique values to the "salesperson assigned" column and adding the revenue for both columns, but when a salesperson is in only ONE table having it respect that there is a zero value for revenue?