Skip to content

Ordering by foreign key count #7875

Discussion options

You must be logged in to vote

Not possible directly for now but you can do so with a computed column.

create function items_count(groups) returns bigint as $$
  select count(*) from items where group_id = $1.id;
$$ stable language sql;
await supabase.from("groups").select('*, items(id)').order('items_count');

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@brycedorn
Comment options

@devalensio
Comment options

@steve-chavez
Comment options

@devalensio
Comment options

@hasanneke
Comment options

Answer selected by brycedorn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants