Structure
SQLSelect
An expression representing a
SELECT query. Used to retrieve rows and expression results from a database.struct SQLSelect
Mentioned in
Overview
SELECT
DISTINCT
"table1"."column1", "table2"."column2", COUNT("table3"."column3") AS "count"
FROM
"table1"
INNER JOIN "table2" ON "table1"."id"="table2"."table1_id"
LEFT JOIN "table3" ON "table2"."id"="table3"."table2_id"
WHERE
"table1"."column1"!=$0
GROUP BY
"table2"."column2", "table3"."column3"
HAVING
"table2"."column2"=$1
ORDER BY
"table1"."column1"
LIMIT 10, 20
LOCK IN SHARE MODE
Note
In any given SQL dialect, SELECT is all but universally the most complex of all queries, offering more variations and features within and between dialects than almost any other self-contained SQL statement. Accordingly, even more so than with other queries, SQLKit cannot hope to offer more than a baseline of common functionality. Some of the more obvious omissions in this version of the package include the WINDOW clause, the INTO (MySQL) or AS (Postgres) clauses, and Common Table Expressions (the WITH clause); support for most or all of these is under consideration for SQLKit’s next major version.
See SQLSelectBuilder.
Topics
Initializers
init()Create a new data retrieval query.
Instance Properties
columnsOne or more expessions describing the data to retrieve from the database.groupByZero or more columns or expressions specifying grouping keys for the filtered result rows.havingisDistinctIftrue, final result rows are deduplicated before being returned.joinsZero or more joins to apply to the overall data sources.limitIf notnil, limits the number of result rows returned. Applies afteroffset(if specified).lockingClauseIf notnil, specifies a locking clause which applies to the rows looked up by the query.offsetIf notnil, skips the given number of result rows before starting to return results.orderByZero or more columns or expressions specifying sort keys and directionalities for the filtered result rows.predicateIf notnil, an expression which filters the source data to determine the result rows.tableExpressionGroupAn optional common table expression group.tablesOne or more tables to include as sources for data to retrieve.
Instance Methods
serialize(to:)Invoked when a request is made to serialize the expression to raw SQL.
Relationships
Conforms To
SQLExpressionSwift.SendableSwift.SendableMetatype
See Also
Query Expressions
SQLAlterEnumAn expression representing anALTER TYPEquery. Used to add new cases to enumeration types.SQLAlterTableAn expression representing anALTER TABLEquery. Used to modify the structure of existing tables.SQLCreateEnumAn expression representing aCREATE TYPEquery. Used to create enumeration types.SQLCreateIndexAn expression representing aCREATE INDEXquery. Used to add indexes over columns to an existing table.SQLCreateTableAn expression representing aCREATE TABLEquery. Used to create new tables.SQLCreateTriggerAn expression representing aCREATE TRIGGERquery. Used to create new triggers for actions on a table.SQLDeleteAn expression representing aCREATE TRIGGERquery. Used to remove rows from a table.SQLDropEnumAn expression representing aDROP TYPEquery. Used to delete enumeration types.SQLDropIndexAn expression representing aDROP INDEXquery. Used to delete indexes from tables.SQLDropTableAn expression representing aDROP TABLEquery. Used to delete entire tables.SQLDropTriggerAn expression representing aDROP TRIGGERquery. Used to delete triggers.SQLInsertAn expression representing anINSERTquery. Used to add new rows to a table.SQLUnionAn expression representing two or moreSELECTqueries joined byUNIONclauses. Used to merge the results of multiple queries into a single result set.SQLUpdateAn expression representing anUPDATEquery. Used to modify existing rows in a single table.