I'm using MySQL 5.7 and have a few problems formulating a recursive query. This is my table:
> show columns from test;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id | int(11) | NO | | NULL | |
| name | varchar(20) | NO | | NULL | |
| belong | varchar(20) | NO | | NULL | |
+--------+-------------+------+-----+---------+-------+
> select * from test;
+----+--------+--------+
| id | name | belong |
+----+--------+--------+
| 1 | value1 | 0 |
| 2 | value2 | 1 |
| 3 | value3 | 2 |
| 4 | value4 | 0 |
| 5 | value5 | 1,4 |
+----+--------+--------+
I would now like to select all records in whose belong field the ID 1 occurs and of course all records that are children of 1. In the example above, all records except the first.
As I have read, recursive queries are only possible from MySQL 8 onwards. So that's no use to me. However, I have also read that you can "simulate" recursion with subqueries and inline variables. But I have to admit that I can't do it and need a little help.