👑️
Size: a a a
👑️
👑️
БГ
select *
from chats
join chat_members on chats.id=chat_members.chat
join messages on chats.id=messages.chat
group by chats.id
order by messages.id desc
БГ
👑️
БГ
БГ
AT
AT
select *
from chats
join chat_members on chats.id=chat_members.chat
join messages on chats.id=messages.chat
group by chats.id
order by messages.id desc
T
👑️
БГ
AT
БГ
AT
БГ
SELECT CASE WHEN m.to_id = 1 THEN m.from_id ELSE m.to_id END AS "interlocutor", u.name, m.id, m.text
FROM messages m
JOIN users u ON
u.id = m.to_id OR u.id = m.from_id
WHERE m.to_id = 1 OR m.from_id = 1
GROUP BY interlocutor
HAVING m.id = max(m.id)
ORDER BY m.id DESC
БГ
SELECT CASE WHEN m.to_id = 1 THEN m.from_id ELSE m.to_id END AS "interlocutor", u.name, m.id, m.text
FROM messages m
JOIN users u ON
u.id = m.to_id OR u.id = m.from_id
WHERE m.to_id = 1 OR m.from_id = 1
GROUP BY interlocutor
HAVING m.id = max(m.id)
ORDER BY m.id DESC