I think the best option is to make a fairly simple choice, put the result in some application and filter it there in a more appropriate (imperative) language. However, if you need my pure MySQL versions. You must order data id.
SELECT a.user_id
FROM notifies AS a
LEFT JOIN notifies AS c ON (
SELECT MIN(id) FROM notifies AS b WHERE b.id > a.id
) = c.id
WHERE a.user_id <> c.user_id OR c.user_id IS NULL
ORDER BY a.id
Second example:
SELECT c.user_id
FROM (
SELECT a.id, a.user_id, MIN(b.id) AS next
FROM notifies AS a
LEFT JOIN notifies AS b ON b.id > a.id
GROUP BY a.id, a.user_id
) AS c
LEFT JOIN notifies AS d ON d.id = c.next
WHERE c.user_id <> d.user_id OR c.next IS NULL
ORDER BY c.id
source
share