I have a table name Agent where storing all the data, and each record are chain to other record, like a tree, How should i retrieve all the LEAF NODE in a SINGLE TABLE with a ROOT NODE ID or a AGENT_ID?
Agent_ID | Agent_name | Recruit_agent_ID
----------------------------------------
1 | Agent1 | Null
----------------------------------------
2 | Agent2 | 1
----------------------------------------
3 | Agent3 | 1
----------------------------------------
4 | Agent4 | 2
----------------------------------------
5 | Agent5 | 3
----------------------------------------
And my desire output should like
ID | Name | Parent
----------------------------------------
2 | Agent2 | 1
----------------------------------------
3 | Agent3 | 1
----------------------------------------
4 | Agent4 | 2
----------------------------------------
5 | Agent5 | 3
----------------------------------------
How can i retrieve all leaf when the given Agent_ID = 1?