I have this:
+----+---------------------+
| id | date |
+----+---------------------+
| 1 | 2017-01-01 12:30:00 |
| 2 | 2017-01-01 12:30:00 |
| 3 | 2017-01-02 00:00:00 |
| 4 | 2017-01-03 00:00:00 |
+----+---------------------+
+----+---------------------+
| id | date |
+----+---------------------+
| 1 | 2017-01-01 12:30:00 |
| 3 | 2017-01-02 00:00:00 |
| 4 | 2017-01-03 00:00:00 |
+----+---------------------+
You could use aggregation:
select min(id) as id, date
from t
group by date;
If you have additional columns, this won't work so well. Instead, use a filter on the where
clause:
select t.*
from t
where t.id = (select min(t2.id) from t t2 where t2.date = t.date);