I have two databases that look like this:
| idElement | idClient | idSubClient | idSport | idCategory | idTeam | idParent |
|-----------|----------|-------------|---------|------------|--------|----------|
| 1 | 1 | -1 | (null) | (null) | (null) | (null) |
| 2 | 1 | -1 | 30 | (null) | (null) | 1 |
| 3 | 1 | -1 | (null) | 100 | (null) | 2 |
| 4 | 1 | -1 | 31 | (null) | (null) | 1 |
| 5 | 1 | -1 | (null) | (null) | 150 | 3 |
| 6 | 1 | -1 | (null) | (null) | 151 | 3 |
| 7 | 1 | -1 | (null) | 101 | (null) | 4 |
| 8 | 1 | -1 | (null) | 101 | (null) | 2 |
| 9 | 1 | -1 | (null) | (null) | 152 | 7 |
| 10 | 1 | -1 | (null) | (null) | 153 | 7 |
| idRef | idElement | idUser |
|-------|-----------|--------|
| 1 | 1 | 2000 |
| 2 | 1 | 2001 |
| 3 | 1 | 2002 |
| 4 | 1 | 2003 |
| 5 | 2 | 2004 |
| 6 | 2 | 2005 |
| 7 | 3 | 2001 |
| 8 | 4 | 2003 |
| 9 | 9 | 2004 |
I want with idUser, idClient, idSubclient create reverse recursive query that returns if parent of element is sport.
For example:
In my case User with id 2004
is assigned to 2
element that is sport but also is assigned to element 9
. The element with id 9
is a team that hangs on category with id 7
in this case it is not a sport then I need to consult his parent to check if is sport...
What I expect
| idElement | |-----------| | 2 | | 4 |