JavaScript: Fetch data

Perform a SELECT query on the table or view.

Parameters

Examples

Getting your data

const \{ data, error \} = await supabase
  .from('countries')
  .select()

Selecting specific columns

const \{ data, error \} = await supabase
  .from('countries')
  .select('name')

Query referenced tables

const \{ data, error \} = await supabase
  .from('countries')
  .select(`
    name,
    cities (
      name
    )
  `)

Query referenced tables through a join table

const \{ data, error \} = await supabase
  .from('users')
  .select(`
    name,
    teams (
      name
    )
  `)

Query the same referenced table multiple times

const \{ data, error \} = await supabase
  .from('messages')
  .select(`
    content,
    from:sender_id(name),
    to:receiver_id(name)
  `)

// To infer types, use the name of the table (in this case `users`) and
// the name of the foreign key constraint.
const \{ data, error \} = await supabase
  .from('messages')
  .select(`
    content,
    from:users!messages_sender_id_fkey(name),
    to:users!messages_receiver_id_fkey(name)
  `)

Query nested foreign tables through a join table

  const \{ data, error \} = await supabase
    .from('games')
    .select(`
      game_id:id,
      away_team:teams!games_away_team_fkey (
        users (
          id,
          name
        )
      )
    `)

Filtering through referenced tables

const \{ data, error \} = await supabase
  .from('cities')
  .select('name, countries(*)')
  .eq('countries.name', 'Estonia')

Querying referenced table with count

const \{ data, error \} = await supabase
  .from('countries')
  .select(`*, cities(count)`)

Querying with count option

const \{ count, error \} = await supabase
  .from('countries')
  .select('*', \{ count: 'exact', head: true \})

Querying JSON data

const \{ data, error \} = await supabase
  .from('users')
  .select(`
    id, name,
    address->city
  `)

Querying referenced table with inner join

const \{ data, error \} = await supabase
  .from('cities')
  .select('name, countries!inner(name)')
  .eq('countries.name', 'Indonesia')

Switching schemas per query

const \{ data, error \} = await supabase
  .schema('myschema')
  .from('mytable')
  .select()