Your data. Anywhere you go.

New Relic for iOS or Android

Download on the App Store    Android App on Google play

New Relic Insights App for iOS

Download on the App Store

Learn more

Close icon

Using a where clause against an alias


I am having an issue with my nrql in which I am trying to apply a where clause against an alias created in the select. below is a simple example where PVPS are all the sessions for each app. I do not want to see any results where pvps is less than 1.
SELECT uniqueCount(session) AS ‘pvps’
FROM PageView
FACET appName

I would suspect something like this
SELECT uniqueCount(session) AS ‘pvps’
FROM PageView
WHERE pvps > 1
FACET appName

I’ve tried multiple variations and nothing seems to work… Does anyone have any ideas?


Hi, @adam1: Unfortunately, the AS operator in NRQL does not create an alias, it merely defines how the value should be labeled in the resulting widget.


Is there a way that I can limit the facet count results to only return where the count is over a given amount?
My problem is that I am trying to identify when a given occurrence happens against a user’s session more than one time. I am getting thousands of one occurrences and each time I run the query I get different results, which I just assumed was a factor of running into limits.

Is there a way to only return where facet count is over one? filter of a filter? buckets? or anything? sort by max?



The only solution I can think of is to use multiple widgets with linked facets:

  • Create a widget that lists sessions by application:

    SELECT uniqueCount(session) FROM PageView FACET appName

  • Create another widget that lists sessions by length (or some other attribute; we just need to SELECT something so we can FACET by session ID):

    SELECT ((MAX(timestamp) - MIN(timestamp)) / 1000 / 60) AS 'Session Length (minutes)' FROM PageView FACET session

  • Create a third widget that SELECTs a list of PageViews:

    SELECT * FROM PageView SINCE 1 day ago

  • Finally, link the first two widgets to the dashboard, so that when the user selects an app name or session ID, the other widgets are filtered to that value: