How do I efficiently retrieve the first n rows of a query result?

select[n]. The first example below retrieves the first 10 rows, whereas the second example retrieves the last 10 rows:

select [10] from table where date=2011.02.27
select [-10] from table where date=2011.02.27

If the table is in memory, you can use the virtual column i to retrieve a specific range of rows:

If you want to retrieve specific rows by index from a partitioned table, use .Q.ind.

C.f. # (take) and sublist