Is there a way to order by relations? e.g. if I ha...
# prisma-client
b
Is there a way to order by relations? e.g. if I have a list of conversations, and each conversation has a list of messages, I'd like to be able to do something like "select the most recent 10 conversations, ordered by the date of the most recent message in each conversation" So I guess this translates to something like
Copy code
SELECT * FROM "Conversation" ORDER BY (SELECT "createdAt" FROM "Message" WHERE "conversationId" = "Conversation".id ORDER BY "createdAt" DESC LIMIT 1) LIMIT 10;
r
I'm not sure if this is still a preview feature or not .. so keep that in mind..
b
Thanks @Richard Ward - it seems like that only works for One-To-One/Many-To-One relations though, as opposed to One-To-Many relations For One-To-Many relations, I can only seem to be able to sort by the number of relations (e.g. order conversations by number of messages that each ones contains)