Vol. I · A Postgres HandbookTwelve chapters · · 756 queries

The Query & the Schema

A reading-room reference for writing PostgreSQL by hand — selects to window functions, with the schema in plain view.

FrontChaptersSchemaColophon
Chapters · Basic SELECT · Query 008 / 136
EasyBasic SELECT

Select all departments and their locations

The query

SQL
SELECT dept_name, location, budget
FROM departments
ORDER BY dept_name ASC;
Tested against PostgreSQL 16

Note

“ASC is the default sort order, so it can be omitted, but explicit is better for readability.

Tables referenced

  • departments5 cols

← Previous

Select employees with column aliases

Next →

Count employees in each department (just count)

The Query & the Schema

Set in Fraunces and Inter Tight. Printed on parchment, in oxblood and ink. No tracking, no accounts, no JavaScript on the answer pages beyond what your browser needs to copy a query.

Compiled for Postgres 16 · MMXXVI