I have 2 tables with the exact same schema. the idea is if table2 is returned null then simply use table1.
CREATE TABLE table1
(
name varchar(10)
);
CREATE TABLE table2
(
name varchar(10)
);
insert into table1
values('abc');
insert into table1
values('xyz');
IF EXISTS (select 1 from table2)
select * from table2;
else
select * from table1;
END IF;