I have a oracle DB with the following columns:
ID / ARTICLE_ID / USER_ID / PARENT / HIERARCHY
100 / 41513151 / 99 / 0 / 100
200 / 12151351 / 101 / 100 / 100|200
300 / 12414144 / 130 / 200 / 100|200|300
This represent a comment (id 100) of the user 99 with a reply of the user 101 to his comment and at the same time this last comment has a reply of the user 130. Graphically.
Hello im user 99 --->Hello im user 101 and this is my reply to the user 99 --------Hello im user 130 and this is my reply to the user 101
So in my db the comment with id 300 his parent is the comment 200 and the last one his parent is the comment 100. HIERARCHY (100 <- 200 <- 300).
I did the following query for delete the comments and subcomments after an user is deleted.
DELETE FROM TABLE_NAME
WHERE (USER_ID = ? AND STATUS IN (1,2)) OR ID in (SELECT A.ID
FROM "TABLE_NAME A INNER JOIN TABLE_NAME B
ON A.PARENT = B.ID
WHERE A.STATUS IN (1,2) AND B.USER_ID=?)
This query works when for each comment just there are a reply, but it exist N replies for each comment (my case), this dont work.
I would like use HIERARCHY for to know that comments are related to a comment of an user deleted taking in account the last idea.
If i build a query as: SELECT ID FROM TABLE_NAME WHERE HIERARCHY LIKE '%X%'
If X was values of the a query or something will be worth, but i think that my battle is lost but something similar is not possible or almost impossible. Am i wrong?.
Cheers