Skip to content
masterclass Buddy

PostgreSQL · Command

SELECT

SELECT retrieves rows from tables, views, subqueries, functions, or other table expressions. It can filter, group, sort, combine, limit, and lock result rows.

Last updated

Syntax

[ WITH [ RECURSIVE ] with_query [, ...] ] SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ] [ { * | expression [ [ AS ] output_name ] } [, ...] ] [ FROM from_item [, ...] ] [ WHERE condition ] [ GROUP BY grouping_element [, ...] ] [ HAVING condition ] [ ORDER BY expression [ ASC | DESC ] [, ...] ] [ LIMIT { count | ALL } ] [ OFFSET start ] [ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } { ONLY | WITH TIES } ] [ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } ... ]

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • TABLE
  • WITH
  • WHERE clause
  • GROUP BY Clause
  • HAVING Clause
  • ORDER BY Clause
  • LIMIT Clause
  • UNION Clause

Source: PostgreSQL: Documentation: 18: SELECT. Checked 2026-11-03.