Querying Data
Learn how to query and filter data from your database.
Note: This is mock/placeholder content for demonstration purposes.
Efficiently query and filter data using Supabase's query builder.
Basic Queries
Select All
const { data, error } = await client
.from('projects')
.select('*');
Select Specific Columns
const { data, error } = await client
.from('projects')
.select('id, name, created_at');
Select with Related Data
const { data, error } = await client
.from('projects')
.select(`
id,
name,
account:accounts(id, name),
tasks(id, title, completed)
`);
Filtering
Equal
const { data } = await client
.from('projects')
.select('*')
.eq('status', 'active');
Not Equal
const { data } = await client
.from('projects')
.select('*')
.neq('status', 'deleted');
Greater Than / Less Than
const { data } = await client
.from('projects')
.select('*')
.gt('created_at', '2024-01-01')
.lt('budget', 10000);
In Array
const { data } = await client
.from('projects')
.select('*')
.in('status', ['active', 'pending']);
Like (Pattern Matching)
const { data } = await client
.from('projects')
.select('*')
.like('name', '%website%');
Full-Text Search
const { data } = await client
.from('projects')
.select('*')
.textSearch('description', 'design & development');
Ordering
Order By
const { data } = await client
.from('projects')
.select('*')
.order('created_at', { ascending: false });
Multiple Order By
const { data } = await client
.from('projects')
.select('*')
.order('status')
.order('created_at', { ascending: false });
Pagination
Limit
const { data } = await client
.from('projects')
.select('*')
.limit(10);
Range (Offset)
const page = 2;
const pageSize = 10;
const from = (page - 1) * pageSize;
const to = from + pageSize - 1;
const { data, count } = await client
.from('projects')
.select('*', { count: 'exact' })
.range(from, to);
Aggregations
Count
const { count } = await client
.from('projects')
.select('*', { count: 'exact', head: true });