I am creating a simple Chat application and I would like to select all Chat and order them by their most recent Message (column created_on) .
The 2 tables are separated and are described as the following:
To achieve that, I wrote the following SQL Script:
SELECT * CHAT AS chat LEFT JOIN MESSAGE AS message ON chat.ID = message.CHAT_ID
GROUP BY chat.ID
ORDER BY message.CREATED_ON
When I run that script, the result are not ordered by most recent Message but instead randomly.
And I also noticed that the Script is not fast.

