The documentation for LIMIT in NRQL (https://docs.newrelic.com/docs/insights/nrql-new-relic-query-language/nrql-resources/nrql-syntax-components-functions#sel-limit) doesn’t describe how it determines which rows are selected to be included in the results.
My own experimentation (as well as the example) implies that the rows are returned in descending order by timestamp for non-facet queries, but descending order by the first aggregated column for facet queries.
Presumably if I’m interested in the “bottom 50” instead of “top 50” for a particular stat, I’d have to express the aggregation as a negative (e.g. “SELECT max(0 - retries) … FACET customer_id LIMIT 20” to get the customers with the fewest retries instead of the most.
Is this correct, and if so, can we rely on this going forward, or is it undocumented and subject to change?