ROWS Syntax in UNION Queries
When ROWS is used in a UNION query, the ROWS directive is applied to the unioned set and must be placed after the last SELECT statement.
If a need arises to limit the subsets returned by one or more SELECT statements inside UNION, there are a couple of options:
-
Use
FIRST/SKIPsyntax in theseSELECTstatements — bearing in mind that an ordering clause (ORDER BY) cannot be applied locally to the discrete queries, but only to the combined output. -
Convert the queries to derived tables with their own
ROWSclauses. -
Use parenthesized query expressions with
OFFSET/FETCH