Section: Querying, Joins, and Aggregation

Basic SELECT

sql
sql
SELECT user_id, email FROM public.users ORDER BY user_id DESC LIMIT 20;
Explanation

See summary for usage details.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Querying, Joins, and Aggregation
Use DISTINCT ON
Pick one row per group using PostgreSQL's `DISTINCT ON` extension.
OpenIn sheetsqlsame section
Inner join
Combine matching rows from two tables.
OpenIn sheetsqlsame section
Common table expression
Use a CTE to structure a multi-step query.
OpenIn sheetsqlsame section
Extract JSONB field
Extract a text value from a JSONB document.
OpenIn sheetsqlsame section
Left join
Keep all rows from the left side even when no match exists.
OpenIn sheetsqlsame section
Group and filter aggregates
Aggregate rows and then filter groups.
OpenIn sheetsqlsame section