I know there are many questions about hierarchical data but what I want is as below. So I have a table like this
| id | name | group_id |
|---|---|---|
| 1 | income | 0 |
| 2 | expenses | 0 |
| 3 | assets | 0 |
| 4 | liabilities | 0 |
| 5 | shipping_related | 2 |
| 6 | direct_expense | 2 |
| 7 | direct_income | 1 |
| 8 | indirect_income | 1 |
| 9 | income_group_1 | 7 |
| 10 | income_group_2 | 7 |
| 11 | expense_group_1 | 5 |
| 12 | expense_group_2 | 6 |
I have many other data in this table. I am just trying to show what I want. I want to get all the subgroups whose group_id is either 1(income) or 2(expenses). I found one solution for this but, it only works for one of them.
In this you can see in the first answer, it is passing 19, I need a query like this with maybe in condition.
EDIT: In MYSQL. Sorry forgot to mention.