© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
6 replies
Funo

Limit select for each entry in "in"

Hey there I am trying to fetch the last message for severeal groups in one select.

  const { data: lastMessages } = await supabase
    .from('messages')
    .select('message')
    .in('group', groups?.map((group) => group.id) || [])
    .order('created_at', { ascending: false })
  const { data: lastMessages } = await supabase
    .from('messages')
    .select('message')
    .in('group', groups?.map((group) => group.id) || [])
    .order('created_at', { ascending: false })

which works fine but gives me back all of the messages of the group. I would like to only get one message for each group in the "in" condition. So if I got four groups with messages in it it should return four rows.
"limit" or "single" only work for the whole amount of rows so I am kind of stuck here.
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Why does the PresenceState contain a list of Presence for each entry?
SupabaseSSupabase / help-and-questions
4y ago
Branch referece in client for each environment
SupabaseSSupabase / help-and-questions
7mo ago
Domain Verification for TXT entry fails
SupabaseSSupabase / help-and-questions
6mo ago
`update().select().limit(1).single()` behavior not consistent
SupabaseSSupabase / help-and-questions
6mo ago