UNION ALL with LIMIT per Branch
UNION ALL with LIMIT per Branch is a SQL statement in the Set Operations category. Use parentheses to apply LIMIT/ORDER BY to individual branches of a UNION before combining. The syntax is (SELECT ... ORDER BY col LIMIT n) UNION ALL (SELECT ... ORDER BY col LIMIT n);. It returns per-branch limited result. A close relative is UNION, which combines results from two queries, removing duplicate rows. Each SELECT must have the same number of columns. A close relative is UNION ALL, which like UNION but does NOT remove duplicate rows. Faster because no dedup is needed. A close relative is INTERSECT, which returns rows that appear in BOTH query results. Supported in PostgreSQL, SQL Server, Oracle. More about this category: Set-based operations — UNION, UNION ALL, INTERSECT, EXCEPT. Related Set Operations entries: UNION, UNION ALL, INTERSECT, EXCEPT / MINUS, INTERSECT ALL / EXCEPT ALL, Ordering Set Operations, TABLE Keyword, Set Operation Precedence.