According to the manual Ingres supports window functions and row_number()
, so you should be able to do:
select coalese(a.rn, b.rn) as rn, a.from_date, b.to_date
from (
select from_date, row_number() over (order by from_date) as rn
from table_a
) a
full join (
select to_date, row_number() over (order by to_date) as rn
from table_b
) b on a.rn = b.rn;
The full (outer) join ensures that rows from both tables are returned even if one tables has fewer rows than the other. If you are 100% sure that both tables always contain the same number of rows, you can use an inner join instead (remove the full
keyword)
I don't have Ingres to test this, so although the above is ANSI standard SQL, there might be things that Ingres does not support
Simpler without full outer join and coalesce()
:
select a.rn, a.from_date, b.to_date
from (
select from_date, row_number() over (order by from_date) as rn
from table_a
) a
join (
select to_date, row_number() over (order by to_date) as rn
from table_b
) b on a.rn = b.rn;