MySQL Forums
Forum List  »  Newbie

get all parents with it's child from single table
Posted by: Surajit Basak
Date: February 05, 2018 02:38PM

Hi, I am trying to use LEFT JOIN to get Parent data first then it's child with — before it.

I have like this table

+----+-------+------+--------+
| id | name | count| parent |
+----+-------+------+--------+
| 1 | parent| 2 | 0 |
+----+-------+------+--------+
| 2 | child | 1 | 1 |
+----+-------+------+--------+
|....| ..... | .... | ..... |
+----+-------+------+--------+

How can I get all parents (after parent then — and it's child) then all remaining parents etc. etc.

I tried to use

SELECT table.id, table.name, table.count as child_data FROM table
LEFT JOIN table AS parent_data ON child_data.parent = parent_data.Id;

But I am getting an error, I know I am doing something wrong with this, please help me to find my mistakes.

Options: ReplyQuote


Subject
Written By
Posted
get all parents with it's child from single table
February 05, 2018 02:38PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.