I have a mysql table like this
+---------+----------------+-------+------------+
| dept_id | parent_dept_id | level | name |
+---------+----------------+-------+------------+
| 1 | 0 | 0 | Company |
| 2 | 1 | 1 | HR |
| 3 | 1 | 1 | Finance |
| 4 | 1 | 1 | Operations |
| 5 | 4 | 2 | Sales |
| 6 | 2 | 2 | Training |
+---------+----------------+-------+------------+
I am trying to retrieve all departments and their parent departments. But what I also want is to retrieve the deprtment with ID 1. This guy is the top department and does not have a parent, all I want is a null in the department name. So far I have this query
select
d1.dept_id,
d2.name as parent_name,
d1.parent_dept_id,
d1.level,
d1.name
from
tdept d1,
tdept d2
where
d1.parent_dept_id = d2.dept_id;
Currently, all departments get retrieved except for the top one, how can I achieve this?