SELECT

Query the database

Synopsis

SELECT statement

Diagram(
  Stack(
    OneOrMore(
      Group(
        Stack(
          Sequence(
            "SELECT",
            Optional("DISTINCT", "skip"),
            OneOrMore(Link("result-field"), ",")
          ),
          Optional(Sequence("FROM", Link("table-name")), "skip"),
          Optional(
            Sequence("WHERE", Link("expr", "/docs/essentials/expressions")),
            "skip"
          ),
          Optional(
            Sequence(
              "GROUP",
              "BY",
              Link("expr", "/docs/essentials/expressions")
            ),
            "skip"
          )
        ),
        "select-core"
      ),
      Choice(0, "UNION", Sequence("UNION", "ALL"))
    ),
    Optional(
      Sequence(
        "ORDER",
        "BY",
        Link("expr", "/docs/essentials/expressions"),
        Optional(Choice(0, "ASC", "DESC"), "skip")
      ),
      "skip"
    ),
    Optional(
      Sequence("LIMIT", Link("expr", "/docs/essentials/expressions")),
      "skip"
    ),
    Optional(
      Sequence("OFFSET", Link("expr", "/docs/essentials/expressions")),
      "skip"
    )
  )
);

Result field

Diagram(
  Choice(
    0,
    Sequence(
      Link("expr", "/docs/essentials/expressions"),
      Optional(Sequence("AS", "field-alias"), "skip")
    ),
    "*"
  )
);

Last modified November 9, 2021: Add CHECK (10b7e10)