Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Selecione o registro mais recente na tabela (campo datetime)

SELECT id, thread_id, user_id, subject, body, date_sent
  FROM messages WHERE date_sent IN (
    SELECT MAX( date_sent )
      FROM messages WHERE user_id =6 GROUP BY thread_id
  )
  ORDER BY thread_id ASC , date_sent DESC;

Deixe-me saber se funcionou agora