I need to write the recursive query to fetch the data in my select query. but it was giving me error with that. I'm writing this query WITH RECURSIVE all_reports AS ( SELECT id, manager_user_id, user_group_id FROM users WHERE manager_user_id=4 UNION ALL SELECT c.id, c.manager_user_id, c.user_group_id FROM all_reports ar, users c WHERE c.manager_user_id=ar.id ) is it possible to write the recursive query? if yes please suggest me what I'm doing wrong. Thanks in advance