Вам нужно написать подзапрос, чтобы получить max
timestamp
на user_id
и device
, а затем self join
SELECT t1.user_id,t1.device,t1.message,t.timestamp
FROM (
SELECT user_id,device,max(timestamp) timestamp
FROM T
GROUP BY user_id,device
) t INNER JOIN T t1 on t.user_id = t1.user_id AND t.timestamp = t1.timestamp
WHERE t1.user_id = 3
sqlfiddle
РЕЗУЛЬТАТ
| user_id | device | message | timestamp |
|---------|---------|---------|----------------------|
| 3 | android | good | 2018-06-03T00:00:00Z |
| 3 | ios | awesome | 2018-06-11T00:00:00Z |