I would like to formulate an SQL Statement like
SELECT x FROM a EXCEPT SELECT x FROM b RIGHT OUTER JOIN table_n ON ... WHERE ...
but can't seem to find the correct syntax. Goal is to first subtract b from a and then outer join it.
I also tried to write it as
SELECT a.x FROM a LEFT OUTER JOIN b ON b.x = a.x WHERE b.x IS NULL RIGHT OUTER JOIN table_n ON ... WHERE ...
with no success.
Any hint is welcome. Regards, Robert
The EXCEPT set operator (like UNION and INTERSECT) works on whole query blocks so it has lower precedence than a join operator.
Try to enclose the EXCEPT statement within braces and use it as a derived query and join it then, such as
SELECT [yourSelectListHere] FROM (SELECT x FROM a EXCEPT SELECT x FROM b) dt RIGHT OUTER JOIN table_n ON dt.x = table_n... WHERE ...
answered 05 Jan '16, 04:05