How to fetch data in a tree structure in MySQL? In a single query
00:11 14 Jun 2018

I have a table in MySQL where each tuple in the table is a child of a tuple in the same table. For that, I'm inserting data primary Id as partner Id. Refer the following for an example.

enter image description here

Here 'A' parent has two children 'B' and 'C', similarly, 'B' has 'D' and 'C' has 'E' as their children respectively. An example is shown in below image

enter image description here

Now, coming to Question, I want to fetch all children of a given parent. Suppose if I pass G's id 7, it should fetch J, K and L records. If I pass A's id 1 it should fetch all records. How can I achieve this in a SQL query? I have no idea on how to build this MySQL query.

mysql