I have two tables with the same column names, and the same composite primary key. The composite primary key of both tables is id + year. I want to always use data from table T1, and if there exists an id + year from table T2, that’s not in table T1 I want it to be returned also.
Here’s my tables
T1
id | year | cost
----+--------+-------
1 | 2012 | 1.01
2 | 2012 | 1.02
2 | 2013 | 1.03
T2
id | year | cost
----+--------+-------
1 | 2012 | 2.01
2 | 2013 | 2.02
3 | 2013 | 2.03
I want to get:
id | year | cost
----+--------+-------
1 | 2012 | 1.01
2 | 2013 | 1.02
2 | 2013 | 1.03
3 | 2013 | 2.03
This is obviously wrong, but I tried:
SELECT
T1.id,
T1.year,
T1.cost
FROM employee_cost AS T1
INNER JOIN (select
employee_cost_historic.id,
employee_cost_historic.year,
employee_cost_historic.cost
from employee_cost_historic) AS T2
ON T1.id = T2.id
AND T1.year = T2.year
You can do this with a
union all: