QueryCommand result = new Query(source, constraint, orderings, columns, limit, distinct);
if (this.firstQuery != null) {
// EXCEPT has a higher precedence than INTERSECT or UNION, so if the first query is
// an INTERSECT or UNION SetQuery, the result should be applied to the RHS of the previous set ...
if (firstQuery instanceof SetQuery && firstQuerySetOperation == Operation.EXCEPT) {
SetQuery setQuery = (SetQuery)firstQuery;
QueryCommand left = setQuery.getLeft();
QueryCommand right = setQuery.getRight();
SetQuery exceptQuery = new SetQuery(right, Operation.EXCEPT, result, firstQueryAll);
result = new SetQuery(left, setQuery.operation(), exceptQuery, setQuery.isAll());
} else {
result = new SetQuery(this.firstQuery, this.firstQuerySetOperation, result, this.firstQueryAll);
}
}
return result;
}