Merging two tables by minimal interval values
I'd approach this in three logical stages:


Expand the rows in both tables for all the days in the month and join them together.
Assign a 'group' to each series of rows where condition and supervisor don't change for a period (a "gaps and islands" problem).
Group the results.


So the solution looks like this:




create table t1(
  id serial primary key
, begin_on integer
, end_on integer
, condition text
);

insert into t1(begin_on,end_on,condition)
values (1,8,'Normal')
     , (8,23,'Critical')
     , (23,30,'Normal');

create table t2(
  id serial primary key
, begin_on integer
, end_on integer
, supervisor text
);

insert into t2(begin_on,end_on,supervisor)
values (1,14,'John')
     , (14,30,'Janice');






select min(g) begin_on, max(g)+1 end_on, condition, supervisor
from( select g
           , condition
           , supervisor
           , row_number() over (order by g) 
             - row_number() over (partition by t1.id, t2.id order by g) grp
      from generate_series(1,30) g
           join t1 on g&gt;=t1.begin_on and g&lt;t1.end_on
           join t2 on g&gt;=t2.begin_on and g&lt;t2.end_on ) z
group by condition, supervisor, grp
order by begin_on;



begin_on | end_on | condition | supervisor
-------: | -----: | :-------- | :---------
       1 |      8 | Normal    | John      
       8 |     14 | Critical  | John      
      14 |     23 | Critical  | Janice    
      23 |     30 | Normal    | Janice    



dbfiddle here

I am assuming this is a cut-down example of your real-world problem or I would also suggest changing the way you store the data in the first place, perhaps using date ranges instead of integers.