Reusing sql query values for another query in single request
I believe you want something like:

SELECT msg.* 
FROM messages msg
JOIN (SELECT chat_id, created_at
  FROM messages
  where id='starting_message_id') nested
ON (msg.chat_id=nested.chat_id and msg.created_at&gt;=nested.created_at)
ORDER BY msg.created_at
LIMIT 6;