Skip to content

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

  • columns
    One or more expessions describing the data to retrieve from the database.
  • groupBy
    Zero or more columns or expressions specifying grouping keys for the filtered result rows.
  • having
    Like predicate, but specifies filtering which applies after groupBy keys are processed.
  • isDistinct
    If true, final result rows are deduplicated before being returned.
  • joins
    Zero or more joins to apply to the overall data sources.
  • limit
    If not nil, limits the number of result rows returned. Applies after offset (if specified).
  • lockingClause
    If not nil, specifies a locking clause which applies to the rows looked up by the query.
  • offset
    If not nil, skips the given number of result rows before starting to return results.
  • orderBy
    Zero or more columns or expressions specifying sort keys and directionalities for the filtered result rows.
  • predicate
    If not nil, an expression which filters the source data to determine the result rows.
  • tableExpressionGroup
    An optional common table expression group.
  • tables
    One 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

See Also

Query Expressions

  • SQLAlterEnum
    An expression representing an ALTER TYPE query. Used to add new cases to enumeration types.
  • SQLAlterTable
    An expression representing an ALTER TABLE query. Used to modify the structure of existing tables.
  • SQLCreateEnum
    An expression representing a CREATE TYPE query. Used to create enumeration types.
  • SQLCreateIndex
    An expression representing a CREATE INDEX query. Used to add indexes over columns to an existing table.
  • SQLCreateTable
    An expression representing a CREATE TABLE query. Used to create new tables.
  • SQLCreateTrigger
    An expression representing a CREATE TRIGGER query. Used to create new triggers for actions on a table.
  • SQLDelete
    An expression representing a CREATE TRIGGER query. Used to remove rows from a table.
  • SQLDropEnum
    An expression representing a DROP TYPE query. Used to delete enumeration types.
  • SQLDropIndex
    An expression representing a DROP INDEX query. Used to delete indexes from tables.
  • SQLDropTable
    An expression representing a DROP TABLE query. Used to delete entire tables.
  • SQLDropTrigger
    An expression representing a DROP TRIGGER query. Used to delete triggers.
  • SQLInsert
    An expression representing an INSERT query. Used to add new rows to a table.
  • 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.
  • SQLUpdate
    An expression representing an UPDATE query. Used to modify existing rows in a single table.