I assume that you are using an inner join with the two tables.
if you are, you could simply issue a query like the following:
select * from tables as a inner join tables2 as b on a.id=b.id order by b.time, a.time desc;
If b.time doesn't exist it should auto default to using a.time as the order by.