Skip to main content

Syntax

Clauses

SELECT

The SELECT clause specifies the columns, expressions, or aggregations you want to retrieve.

FROM

The FROM clause specifies the source table(s), subquery, or table function to query from.

WHERE

The WHERE clause filters rows based on specified conditions. It supports various comparison and logical operators.

GROUP BY

The GROUP BY clause groups rows by specified columns and is typically used with aggregate functions. Supports additional modifiers:
  • WITH ROLLUP: Adds extra rows with subtotals
  • WITH CUBE: Adds subtotals for all possible combinations
  • WITH TOTALS: Adds a final row with totals

HAVING

The HAVING clause filters grouped results based on aggregate conditions.

ORDER BY

The ORDER BY clause sorts results by specified columns. Supports additional features:
  • WITH FILL: Fills missing values in sorted results
  • INTERPOLATE: Specifies how to interpolate missing values

JOIN

Propel supports various types of joins to combine rows from two or more tables based on a related column between them.
  • LEFT JOIN
The LEFT JOIN returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side if there is no match.
  • RIGHT JOIN
The RIGHT JOIN returns all records from the right table (table2), and the matched records from the left table (table1). The result is NULL from the left side if there is no match.
  • FULL JOIN
The FULL JOIN returns all records when there is a match in either left (table1) or right (table2) table records. If there is no match, the result contains NULL values for columns from the table without a match.
  • INNER JOIN
The INNER JOIN returns all records when there is a match in both left (table1) and right (table2) table records.

DISTINCT, UNION, and ALL

  • DISTINCT
The DISTINCT clause is used to return only unique values in the result set.
  • UNION
The UNION operator is used to combine the result sets of two or more SELECT statements.
  • UNION ALL
The UNION ALL operator is used to combine the result sets of two or more SELECT statements, including duplicates.

WITH

The WITH clause is used to define a common table expression (CTE).

LIMIT

The LIMIT clause controls the number of rows returned. It supports several formats:
  • Basic LIMIT with optional OFFSET
  • LIMIT BY to limit rows per group
  • WITH TIES to include rows that match the last row

WINDOW

The WINDOW clause defines named window specifications for window functions.

QUALIFY

The QUALIFY clause filters results based on window functions.

SAMPLE

The SAMPLE clause allows you to query a random sample of rows.

ARRAY JOIN

The ARRAY JOIN clause allows you to join with array or nested data structures.

FORMAT

The FORMAT clause specifies the output format of the query results.

INTO OUTFILE

The INTO OUTFILE clause writes query results to a file.

SETTINGS

The SETTINGS clause allows you to specify query-specific settings.