SELECT a.path,b.path from comm_department_temp a INNER JOIN comm_department_temp b on a.id=b.parent_id where a.path!=left(b.path,length(b.path)-3)