Database
Order the results
Order rows by one or more columns. Chains; multiple calls accumulate.
Add an ORDER BY clause. Lives on the select (and rpc) builder via SelectMixin. Each call appends to the existing order — call it once per column for multi-key sorts.
Signature
builder.order(column, desc: false, nullsfirst: nil, foreign_table: nil)Parameters
| Name | Type | Required | Description |
|---|---|---|---|
column | String / Symbol | Required | Column name to order by. Passed verbatim to the PostgREST order= query string. |
desc | Boolean | Optional | When true, sort descending. Default false (ascending). |
nullsfirst | Boolean, nil | Optional | true → nullsfirst, false → nullslast, nil (default) → omit the directive and let Postgres decide. |
foreign_table | String | Optional | Order an embedded resource. Rewrites the query key to <foreign_table>.order so PostgREST applies the order to the joined relation, not the parent. |
Returns
Returns
self (SelectRequestBuilder)
The same builder, so you can keep chaining other modifiers / filters before .execute.
Example — ascending by name
response = supabase
.from("countries")
.select("id, name")
.order("name")
.executeExample — descending with nulls last
response = supabase
.from("users")
.select("id, last_login")
.order("last_login", desc: true, nullsfirst: false)
.executeExample — multi-column ordering
Call order once per column. The builder concatenates them with a comma, exactly like PostgREST expects.
supabase
.from("orders")
.select("id, customer_id, total")
.order("customer_id")
.order("total", desc: true)
.executeExample — order an embedded resource
foreign_table: targets the joined relation. Use it with a select that embeds the table.
supabase
.from("authors")
.select("name, books(title, published_at)")
.order("published_at", desc: true, foreign_table: "books")
.execute