I am using MYSQL 5.7. I want to get the last lines with excellent device_id . I tried these queries:
Request 1
SELECT `table`.`id`, `table`.`device_id` FROM `table` WHERE (id IN (SELECT id FROM (SELECT * FROM table ORDER BY date_modified DESC) AS last_modified GROUP BY device_id) and device_id <> ''); +
But this does not remove duplicates.
Subquery 1
SELECT id FROM (SELECT * FROM table ORDER BY date_modified DESC) AS last_modified GROUP BY device_id; ERROR 1055 (42000): Expression
This gave an error. Then I found on the MySQL website to use ANY_VALUE () to remove this error.
Subquery 2
SELECT ANY_VALUE(id) FROM (SELECT * FROM table ORDER BY date_modified DESC) AS last_modified GROUP BY device_id; +
This gives excellent identifiers. But when I use ANY_VALUE in query 1 above, it gives the same result.
How to query individual last rows in MySQL 5.7?
Possible duplicate
MySQL 5.7 returns all columns of a table based on a single column
source share