Intersect in NRQL


I need to intersect the result of 2 separate queries but I noticed that NRQL does not support it. I’m talking about sql intersect - tutorialSQL2012

Is there any alternative to do it with NRQL?


Hi, @Carlos.X.Navas_ND: You may be able to do it with a nested query. If you can provide more details about what you are trying to do, we may be able to help you.

hi @philweber let’s say I have 2 separate queries.

  • select user_id from Incident WHERE (status=‘active’ and type=‘1’) or status=‘resolved’
  • select user_id from Incident WHERE status=‘resolved’

I need to determine the intersection between above 2 queries. From the above example I need to determine the users who recovered from a particular type of incident (active and type=1).

The example is just illustrative.

Couldn’t you do that with a single query?

select user_id from Incident WHERE (status='active' and type='1') and name='resolved'

@philweber sorry, I’ve just updated my queries above. Basically I want to list users who had a particular incident (status=‘active’ and type=‘1’) but they were able to fix it (status=resolved).

I am still not understanding why you need an INTERSECT for this. Why not:

SELECT user_id FROM Incident WHERE type = '1' AND status = 'resolved'
1 Like

Anyway, if you have a situation where you truly need an INTERSECT in NRQL, nested queries are the nearest equivalent.