How do I select the nth last row from a table in sqlite3 database (Python)?
(with an Id Column in ascending order)
How do I select the nth last row from a table in sqlite3 database (Python)?
(with an Id Column in ascending order)
There is no such thing as the nth last row in a table. In SQL tables represent unordered sets.
If you have a column that specifies the ordering, you can use:
select t.*
from t
order by <ordering column> desc
limit 1 offset n - 1;
In SQLite, tables are often created with rowid
as a column that is often used to represent the insert order (although that might not always be true). That may be what you want to use as the ordering column.