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.
Example #1
This query finds the number of transactions whose duration is above average:
SELECT count(*) FROM Transaction WHERE duration > (SELECT average(duration) FROM Transaction)
Example #2
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)))
Demo
See how it works in the following video:
Get started
- Review the documentation and then try out your own queries!
- Read the blog for tips on using subqueries and see a few subquery examples.
- Share your feedback, post your own subqueries, and see even more examples in the Explorers Hub discussion post.