SupabaseS
Supabase2y ago
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 })

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.
Was this page helpful?