I’m using some academic DBMS and don’t know does it implement limit/top feature. Is it possible to achieve the same using any other technique?
Say I have next tables:
Movies
MovieId
Title
Year
Actors
ActorId
Name
ActorInMovie
ActorId
MovieId
And what get the latest by year movie of given by name actor, e.g.:
select m.Title, m.Year
from ActorInMovie in
join Movies m on m.MovieId = in.MovieId
join Actors a on a.ActorId = in.ActorId
where
a.Name = 'Bruce Willis'
and m.Year = ...
A couple of thoughts:
Use a window function (e.g.,
ROW_NUMBER()) in a subquery and select where the row number is 1. But if your DBMS isn’t sophisticated enough to have TOP/LIMIT, it seems unlikely that it would have window functions.Insert the results into a table with an auto-incrementing identity type column. Then select where that identity column is 1.