I have table master_employee and fields employee_code, employee_name, cam_manager_code. my code:
SELECT
me.employee_name as employee_name,
me_cam.employee_name as cam_manager_name,
me.employee_code
FROM master_employee as me_cam
LEFT JOIN master_employee as me ON me.cam_manager_code = me_cam.employee_code AND me.deleted = 'N'
WHERE me.cam_manager_code = NULL
ORDER BY cam_manager_name, employee_name;
SIMPLE EXAMPLE
my table
id | name | parent_id
1 | a | NULL
2 | a1 | 1
3 | a2 | 1
4 | b | NULL
5 | b1 | 4
6 | b2 | 4
result :
name | parent_name
a1 | a
a2 | a
a | NULL
b1 | b
b2 | b
b | NULL
I want parent row after childs, example parent a after child a1 and a2