What SQL environment are you using? The answer will depend on the environment.
Also, how are the records ordered? Are they sorted in some fashion, or do you want them in natural order?
Looking at your example and assuming your ids column is the order you want them sorted in, you could use a query like this for MS SQL Server
select
top (20-12) ids, code
from
[yourtable]
where
ids in (SELECT TOP 20 id from stoplists order by id)
order by
ID desc
e.g. grab the first X records you want, and then grab the records you want from that result set.
You can achieve the same things in other SQL syntaxes with a slightly different syntax.