Here is a way of getting the desired results without using a common table expression (CTE).
declare @Exam as table (id varchar(5), theDateTime datetime);
declare @Lecture as table (id varchar(5), theDateTime datetime);
insert into @Exam values ('ex1','2014-08-07 13:21:48.000');
insert into @Exam values ('ex2','2014-08-07 14:21:48.000');
insert into @Exam values ('ex3','2014-08-06 13:21:48.000');
insert into @Exam values ('ex4','2014-08-05 13:21:48.000');
insert into @Lecture values ('l1','2014-08-07 11:21:48.000');
insert into @Lecture values ('l2','2014-08-07 12:21:48.000');
insert into @Lecture values ('l3','2014-08-06 11:21:48.000');
insert into @Lecture values ('l4','2014-08-05 12:21:48.000')
select top 5
id,
theDateTime
from (
select id, theDateTime from @Exam
union all
select id, theDateTime from @Lecture
) ExamAndLecture
order by theDateTime desc;
I am not sure which version will run faster, but I assume there will not be much difference in the speed of execution.
I have included the cte version below so you may test and compare the difference or similarity in the query structure.
with ExamAndLecture(id, theDateTime) as (
select id, theDateTime from @Exam
union all
select id, theDateTime from @Lecture
)
select top 5
id,
theDateTime
from ExamAndLecture
order by theDateTime desc;