New Relic Query Language(NRQL) just got more powerful! With subqueries, you can now dive deeper to expand your analysis to include data from different data sources, time ranges, and entities in a single query.
A subquery is simply a NRQL query which is embedded inside of another query. Each subquery is evaluated, then the result is used during the execution of the outer query.
NRQL subquery examples
Here are two examples. For more details on how to use subqueries, see the examples in the docs.
This query finds the number of transactions whose duration is above average:
SELECT count(*) FROM Transaction WHERE duration > (SELECT average(duration) FROM Transaction)
This query leverages multiple nested subqueries to find the unique accounts responsible for transactions whose duration was greater than the 99th percentile:
FROM Transaction SELECT uniques(accountId) WHERE guid IN (FROM Transaction SELECT uniques(guid) WHERE duration > (FROM Transaction SELECT percentile(duration, 99)))
See how it works in the following video:
Suggest a change and learn how to contribute