This is what are you looking for
SELECT
`t1`.*
FROM
`messages` `t1`
INNER JOIN
(
SELECT
MAX(`id`) as `latest`,
`user_id`
FROM
`messages`
GROUP BY
`user_id`) `t2`
ON
`t1`.`user_id` = `t2`.`user_id` AND
`t1`.`id` = `t2`.`latest`
solved this is sql table tbl_message distinct records by user_id but last id display mins DESC record form id [closed]