My table structure is:
COMPANY_ID, ID, PARENT_ID
Here is some part from this table:
| COMPANY_ID | ID | PARENT_DID |
|------------|-------------|-------------|
| 12 | 1 | null |
| 12 | 3 | 1 |
| 12 | 2 | 1 |
| 12 | 4 | 3 |
| 12 | 7 | 4 |
| 14 | 3 | null |
I want to find all child and grandchild IDs for any ID in Oracle 10g. The result must be like this for COMPANY_ID=12 and ID=3:
3, 4, 7
I have tried this, but this not working:
SELECT id
FROM TABLE_NAME
START WITH ID = 3
CONNECT BY PARENT_ID = PRIOR ID
AND COMPANY_ID=12;