nsag
nsag

Reputation: 3

Compare rows values of same table in mysql

I have data like this:

header_id | class | start_date | end_date
-------------------------------------------
1         | c1    | 20-08-2019 | 22-08-2019
1         | c1    | 22-08-2019 | 24-08-2019
1         | c2    | 24-08-2019 | 27-08-2019
2         | c3    | 25-08-2019 | 26-08-2019
2         | c3    | 26-08-2019 | 30-08-2019
3         | c1    | 23-08-2019 | 26-08-2019

I want to get the following results:

header_id | class | start_date | end_date
-------------------------------------------
1         | c1    | 20-08-2019 | 24-08-2019
1         | c2    | 24-08-2019 | 27-08-2019
2         | c3    | 25-08-2019 | 30-08-2019
3         | c1    | 23-08-2019 | 26-08-2019

Is there a way to get that result ?

Upvotes: 0

Views: 60

Answers (1)

Anatoliy R
Anatoliy R

Reputation: 1789

Form what I understood, you need something like this:

select header_id. class, min(start_date), max(end_date)
from your_table_name
group by header_id, class

Change your_table_name to the actual name

Upvotes: 2

Related Questions