Structure
SQLUnion
An expression representing two or more
SELECT queries joined by UNION clauses. Used to merge the results of multiple queries into a single result set.struct SQLUnion
Overview
(SELECT ...)
UNION ALL
(SELECT ...)
INTERSECT DISTINCT
(SELECT ...)
EXCEPT ALL
(SELECT ...)
There are numerous variations in support and syntax for UNION joiners between dialects; this expression respects dialect differences to the extent possible but will someimtes generate invalid SQL if an operation unsupported by the current dialect is described by its inputs.
See SQLUnionBuilder.
Topics
Initializers
init(initialQuery: SQLSelect, unions: [(SQLUnionJoiner, SQLSelect)])Create a new set of combined queries.
Instance Properties
var initialQuery: SQLSelectThe required first query of the union.var limit: Int?If notnil, limits the number of result rows returned. Applies afteroffset(if specified).var offset: Int?If notnil, skips the given number of result rows before starting to return results.var orderBys: [any SQLExpression]Zero or more columns or expressions specifying sort keys and directionalities for the overall result rows.var tableExpressionGroup: SQLCommonTableExpressionGroup?An optional common table expression group.var unions: [(SQLUnionJoiner, SQLSelect)]Zero or more additional queries whose results are to be combined with that of the initial query and associated joiner expressions describing the combining operation.
Instance Methods
func add(SQLSelect, all: Bool)Add an additional query to the union using theUNIONorUNION ALLjoiner.func add(SQLSelect, joiner: SQLUnionJoiner)Add an additional query to the union using the provided joiner.func serialize(to: inout SQLSerializer)Invoked when a request is made to serialize the expression to raw SQL.
Relationships
Conforms To
SQLExpressionSwift.SendableSwift.SendableMetatype
See Also
Query Expressions
struct SQLAlterEnumAn expression representing anALTER TYPEquery. Used to add new cases to enumeration types.struct SQLAlterTableAn expression representing anALTER TABLEquery. Used to modify the structure of existing tables.struct SQLCreateEnumAn expression representing aCREATE TYPEquery. Used to create enumeration types.struct SQLCreateIndexAn expression representing aCREATE INDEXquery. Used to add indexes over columns to an existing table.struct SQLCreateTableAn expression representing aCREATE TABLEquery. Used to create new tables.struct SQLCreateTriggerAn expression representing aCREATE TRIGGERquery. Used to create new triggers for actions on a table.struct SQLDeleteAn expression representing aCREATE TRIGGERquery. Used to remove rows from a table.struct SQLDropEnumAn expression representing aDROP TYPEquery. Used to delete enumeration types.struct SQLDropIndexAn expression representing aDROP INDEXquery. Used to delete indexes from tables.struct SQLDropTableAn expression representing aDROP TABLEquery. Used to delete entire tables.struct SQLDropTriggerAn expression representing aDROP TRIGGERquery. Used to delete triggers.struct SQLInsertAn expression representing anINSERTquery. Used to add new rows to a table.struct SQLSelectAn expression representing aSELECTquery. Used to retrieve rows and expression results from a database.struct SQLUpdateAn expression representing anUPDATEquery. Used to modify existing rows in a single table.