it's my first post so I hope you help me to find a solution to my problem :)
I have 2 columns, idParent and idChild. If I want to represent that Parent id=1 has 2 children (id=2 & id=3), we find:
+--------------------+
| idParent idChild |
+--------------------+
| 1 2 |
| 1 3 |
+--------------------+
Well, my goal is starting from a idChild, find all his "top" parents (parents that have no parents) in a single query, if is possible.
Sample:
+--------------------+
| idParent idChild |
+--------------------+
| 1 3 |
| 2 4 |
| 2 5 |
| 3 5 |
| 3 6 |
| 5 7 |
+--------------------+
Expected result (if we start to querying with idChild=7):
+----------+
| idParent |
+----------+
| 1 |
| 2 |
+----------+
I don't know if I can solve my problem with a single query. My other option would be create a easy query that returns the parents from a child and invoke it many times since my Java code (much more inefficient).
Thanks!
Note: If it helps, I have to use CriteriaQuery API to access data.