How to add a subquery to the query to display the last message in the room?
Chat rooms
id, type(USER_TO_USER, USER_TO_SHOP, USER_TO_PLATFORM), name
list of messages
room_messages - id, participant_id, text, is_read
my query
select r.id, r.name from rooms as r
left join room_participants rp on r.id = rp.room_id
where rp."participantType" = 'USER' and rp.participant_id = 1
2
Answers
Tweaked a little
You need to first get the last message of each room, then join the rest tables: