I have a very long query which uses distinct intersect, when the query grows too long and I execute it it throws above exception
SELECT DISTINCT RTypeId FROM dbo.User_Res WHERE UserId = '1749'
INTERSECT SELECT DISTINCT RTypeId FROM dbo.User_Res WHERE UserId = '424'
INTERSECT SELECT DISTINCT RTypeId FROM dbo.User_Res WHERE UserId = '1906'
INTERSECT SELECT DISTINCT RTypeId FROM dbo.User_Res WHERE UserId = '725'
INTERSECT SELECT DISTINCT RTypeId FROM dbo.User_Res WHERE UserId = '1596'
Can you please help me with an alternative to this query?
Error msg:
The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that reference a very large number of tables or partitions. Please simplify the query.