Thanks; that to me looks a truly amazing SQL! As you say doing this in code might be more efficient and definitely less confusing. In fact when doing something as you suggest: select * from MyTable where ID <= 14 order by ID desc I can make it a lot more efficient by adding a limit as not many records will be needed.
RBS On Sun, Nov 20, 2011 at 12:15 AM, Igor Tandetnik <itandet...@mvps.org> wrote: > Bart Smissaert <bart.smissa...@gmail.com> wrote: >> If we have the 14 (we know to start at 14) can we select the records >> 14, 13, 12 and 11, >> so the consecutive numbers, going down from 14? > > select * from MyTable t1 where > (select count(*) from MyTable t2 where t2.ID between t1.ID and 14) == 14 - > t1.ID + 1; > > Personally, I'd just run a query like > > select * from MyTable where ID <= 14 order by ID desc; > > and step through it until the next ID is non-consecutive. > -- > Igor Tandetnik > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users