JavaScript: Fetch data

Perform a SELECT query on the table or view.

Parameters

Examples

Getting your data

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

Selecting specific columns

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

Query referenced tables

const { data, error } = await supabase .from('orchestal_sections') .select(` name, instruments ( name ) `) 

Query referenced tables with spaces in their names

const { data, error } = await supabase .from('orchestal sections') .select(` name, "musical instruments" ( 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('instruments') .select('name, orchestral_sections(*)') .eq('orchestral_sections.name', 'percussion') 

Querying referenced table with count

const { data, error } = await supabase .from('orchestral_sections') .select(`*, instruments(count)`) 

Querying with count option

const { count, error } = await supabase .from('characters') .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('instruments') .select('name, orchestral_sections!inner(name)') .eq('orchestral_sections.name', 'woodwinds') .limit(1) 

Switching schemas per query

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