I have a table something like below, It represents employees hire_date in the company. If the end date is null it means that these employees working with the company. For example in this table employee_id 2 has multiple records, which means that this employee was promoted inside the company.
emp_id |start_date |end_date |
--------------------------------
1 |1/1/2020 |12/12/2020 |
--------------------------------
2 |2/2/2020 |5/5/2020 |
--------------------------------
3 |9/9/2020 |null |
--------------------------------
2 |5/5/2020 |1/1/2021 |
--------------------------------
2 |1/1/2021 |null |
--------------------------------
What I want is to get the list of the employees with min(start_date) and max(end_date). if the end date is null then this null will be considered as a max date.
from above table expected output will be like below:
emp_id |start_date |end_date |
--------------------------------
1 |1/1/2020 |12/12/2020 |
--------------------------------
2 |2/2/2020 |null |
--------------------------------
3 |9/9/2020 |null |
--------------------------------
Currently, I am using multiple queries to achieve it. Please note that I am using postgresql.