Skip to main content
Version: v2 RC

order()

Order the query result by column.

You can call this method multiple times to order by multiple columns.

You can order foreign tables, but it doesn't affect the ordering of the current table.

const { data, error } = await supabase
.from('cities')
.select('name', 'country_id')
.order('id', { ascending: false })

Parameters

  • columnrequiredColumnName

    The column to order by

  • optionsoptionalobject

    Named parameters

      Properties
    • ascendingoptionalboolean

      If true, the result will be in ascending order

    • foreignTableoptionalundefined

      Set this to order a foreign table by foreign columns

    • nullsFirstoptionalboolean

      If true, nulls appear first. If false, nulls appear last.

Examples

With select()

const { data, error } = await supabase
.from('countries')
.select()
.order('name', { ascending: false })

On a foreign table

Ordering on foreign tables doesn't affect the ordering of the parent table.

const { data, error } = await supabase
.from('countries')
.select(`
name,
cities (
name
)
`)
.order('name', { foreignTable: 'cities', ascending: false })