I have two Redshift tables which get joined on an id and a date in a specific date range.
When I try to full-outer-join the tables (both alternative SQL statements further down below), I get the following error:
[Amazon](500310) Invalid operation: FULL JOIN is only supported with merge-joinable join conditions; [SQL State=0A000, DB Errorcode=500310]
It works for LEFT-JOIN, but not for FULL-OUTER. I basically want to have all ids and ranges in there, even if there were no matches in the other table. How can I solve this error?
Table 1:
- id
- colx (date)
Table 2:
- id
- col2 (date range beginning)
- col3 (date range end)
- something
First alternative join:
SELECT *
FROM table1
FULL OUTER JOIN table2
ON (table1.id = ltrim(table2.id, '0') -- id
AND DATE(table1.colx) BETWEEN DATE(table2.col2) AND DATE(table2.col3) -- date range
)
;
Second alternative join: (according to the AWS documentation, the range is inclusive, so the statements should have the same results I suppose)
SELECT *
FROM table1
FULL OUTER JOIN table2
ON table1.id = ltrim(table2.id, '0') -- id
AND DATE(table1.colx) >= table2.col2 -- date range beginning
AND DATE(table1.colx) <= table2.col3 -- date range ending
;