create table A (
dt date,
v varchar(5)
);
insert into A values ('2013-05-05','xxxx1');
insert into A values ('2013-05-07','xxxx2');
insert into A values ('2013-05-08','xxxx3');
create table B(
dt date
);
insert into B values ('2013-05-06');
insert into B values ('2013-05-07');
select B.dt,
case when A.dt is not null then A.v else A_max.v end as v
from B
join (select max(v) as v from A) as A_max ON 1=1
left join A ON B.dt = A.dt
order by 1
create table A (
dt date,
v varchar(5)
);
insert into A values ('2013-05-05','xxxx1');
insert into A values ('2013-05-07','xxxx2');
insert into A values ('2013-05-08','xxxx3');
create table B(
dt date
);
insert into B values ('2013-05-06');
insert into B values ('2013-05-07');
select B.dt,
case when A.dt is not null then A.v else A_max.v end as v
from B
join (select max(v) as v from A) as A_max ON 1=1
left join A ON B.dt = A.dt
order by 1