SELECT *
FROM (SELECT ticket.name as ticket_name, tm.text as message_text, tm.created_at as message_dt, ROW_NUMBER() OVER(PARTITION BY ticket.user_id ORDER BY tm.created_at DESC, tm.id DESC) AS rn
FROM
ticket_themes ticket
LEFT JOIN ticket_message tm on ticket.id = tm.theme_id
WHERE ticket.user_id = 69625 ) t
WHERE t.rn = 1