I have a question regarding SQL, I have never worked with sub-selects and I ended up getting lost with it.
My SQL:
SELECT CLI.id, CLI.nome, CLI.senha, CLI.email, CLI.cpf, CLI.celular, CLI.data_nasc, CLI.genero, CLI.data_cadastro, CLI.status, CLI.id_socket, ATEN.mensagem, ARQ.nome AS foto, ATEN.data_mensagem
FROM ut_clientes AS CLI
LEFT JOIN ut_arquivos AS ARQ ON (ARQ.id_tipo = CLI.id AND ARQ.tipo = "ut_clientes")
INNER JOIN ut_atendimentos AS ATEN ON (ATEN.id_usuario_envio = CLI.id)
WHERE ATEN.id_usuario_envio != 1
GROUP BY CLI.id
ORDER BY ATEN.data_mensagem
DESC
Well, what I would like to do was group the messages according to the customer ID and bring only the last message recorded in the database according to the message_message.
I have tried in many ways but always the last one that is displayed is the first message inserted in the database.