JavaScript: Order the results

Order the query result by column.

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

You can order referenced tables, but it only affects the ordering of the parent table if you use !inner in the query.

Parameters

Examples

With `select()`

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

On a referenced table

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

Order parent table by a referenced table

  const { data, error } = await supabase
    .from('instruments')
    .select(`
      name,
      section:orchestral_sections (
        name
      )
    `)
    .order('section(name)', { ascending: true })