It will be better to use primary key or unique column(s) than ROWID.
One reason is meaningful order of rows for first and last rows.
Another reason is repeatability.
Here is a related discussion by Andy(Yesterday, 21:31 by ARWinner):
Need Help for a query
I like to use ROWNUMBER() OLAP expression, like this:
Code:
SELECT col1, col2, ...
FROM (SELECT col1, col2, ...
, ROWNUMBER() OVER(ORDER BY sort_key1 ASC , sort_key2 ASC , ...) AS rn_asc
, ROWNUMBER() OVER(ORDER BY sort_key1 DESC, sort_key2 DESC, ...) AS rn_desc
FROM <table>
WHERE .....
) q
WHERE rn_asc = 1
OR rn_desc = 1
;