0
votes

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?

2
Show us what you tried - cymruu

2 Answers

0
votes

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
0
votes

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.