I have two tables as below:
TableA
ID | link1 | link2 | DATE_FROM | DATE_TO |
---|---|---|---|---|
99 | H | J | 1999-01-01 | 2005-01-01 |
TableB
ID | link1 | link2 | DATE_FROM | DATE_TO |
---|---|---|---|---|
99 | X | Y | 2002-01-01 | 2008-01-01 |
And I want to query them and retreive the result below:
ID | A.link1 | A.link2 | B.link1 | B.link2 | DATE_FROM | DATE_TO |
---|---|---|---|---|---|---|
99 | H | J | 1999-01-01 | 2002-01-01 | ||
99 | H | J | X | Y | 2002-01-02 | 2005-01-01 |
99 | X | Y | 2005-01-02 | 2008-01-01 |
It seems like I should be able to do this with sql using some kind of between join and perhaps some unions but I can't quite wrap my head around it. Can anyone tell me how can this result be produced please? Thanks