SELECT DISTINCT (a.id) FROM test1 a INNER JOIN test1 b ON a.id = b.id WHERE a.date = '2016-10-16 00:00:00' AND b.date < '2016-10-16 00:00:00' ORDER BY a.id