My monetdb table has over 100k rows. I want to select the last n rows from the table. Will it be possible to query only the last n records without scanning the entire table?
Asked
Active
Viewed 322 times
0
-
Show us what you tried – cymruu Mar 21 '17 at 06:27
2 Answers
0
for Transact SQL:
SELECT *
FROM [your_table] AS tbl
ORDER BY 1 DESC
TOP n
or others (SQL Standard):
SELECT *
FROM [your_table] AS tbl
ORDER BY 1 DESC
LIMIT n

fosjo
- 27
- 2
0
The only reliable way of doing this is by having a column with an increasing time stamp or id value that you can ORDER BY.
Especially if there are no deletes, MonetDB will notice that this column is sorted and use this fact to quickly locate the latest rows.

Joeri van Ruth
- 181
- 4