Reputation: 25
Ok, so I have a table that looks like so with replicated id fields each with different start and end dates:
id startDate endDate
4052021011 2021-05-04 12:11:39 2021-05-04 12:16:54
4052021011 2021-05-04 12:20:50 2021-05-04 12:22:04
4052021011 2021-05-04 12:25:37 2021-05-04 12:32:08
And I want to perform a query that takes the earliest start date, the lastest end date from the same id and retuns the following:
id startDate endDate
4052021011 2021-05-04 12:11:39 2021-05-04 12:32:08
Any help would be really appreciated.
Probably worth mentioning that I am using mySQL.
Upvotes: 1
Views: 180
Reputation: 1269753
This sounds like aggregation:
select id, min(startDate), max(endDate)
from t
group by id;
Do you have something actually more complex than this? GROUP BY
is very basic SQL functionality.
Upvotes: 1