Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Some notes about BETWEEN - this does not matter in my case. Selecting +-1 row at the beginning or the end of a range will not break the algorithm. Thank you for pointing it out, though :)
I suppose, sub query should also contain p.obj_id = 42 condition. Works like a charm, thank you! One more question: is there any neat way to select one row, when all the rows contains the same data? Your query returns zero rows in this case: sqlfiddle