Skip to content

SQL Operators

SELECT

SELECT [expression] FROM tbl, ...;

WHERE

WHERE <condition> [AND|OR <condition> ...];

JOIN

[LEFT|RIGHT|INNER] JOIN tbl ON <condition> [AND|OR <condition> ...];

GROUP BY

GROUP BY <expression>, ...;

GROUP BY supports the following aggregations:

  • COUNT
  • SUM
  • MAX
  • MIN
  • AVG
  • ARRAY_AGG
  • JSON_AGG
  • STRING_AGG

Note that these aggregations are also available without a GROUP BY expression

UNION/UNION ALL

SELECT ... UNION [ALL] SELECT ...;

ORDER BY ... LIMIT

ORDER BY <expression>, ... [ASC|DESC] LIMIT <const>;

DISTINCT

SELECT DISTINCT [ON (<expression>, ...)] ...;

CTEs

WITH <cte_name> AS (SELECT ...), ... SELECT ...;

Subqueries and Views

SELECT ... FROM (SELECT ...) AS <alias>, ...;
SELECT ... FROM <view_name>, ...;