querybuilder icon indicating copy to clipboard operation
querybuilder copied to clipboard

Unable to provide explicit precedence on combinations such as UNION and INTERSECT

Open alexmg opened this issue 4 years ago • 1 comments

It does not seem to be possible to be explicit about the precedence when applying more than one combination.

In the example below, without the additional parentheses the INTERSECT will take precedence over the UNION.

(SELECT 1

UNION

SELECT 2)

INTERSECT

SELECT 2

Is there a way to workaround this issue and add parentheses as needed to enforce the desired precedence?

alexmg avatar May 07 '20 01:05 alexmg

I'm having the same issue

rafael-queiroz-cko avatar Jun 15 '20 14:06 rafael-queiroz-cko

Not 100% identical but with subqueries you can achieve the same result

var query = 
new Query().From(
    new Query("A").Union(new Query("B")).As("U1")
).Intersect(new Query("C"));

Will output

SELECT * FROM (SELECT * FROM [A] UNION SELECT * FROM [B]) AS [U1] INTERSECT SELECT * FROM [C]

Union and Intersect example

ahmad-moussawi avatar Oct 02 '22 09:10 ahmad-moussawi