I am having a table name factors
. It contains data like this:
id Name paretnID
1 abc 0
2 xyz 0
3 abc1 1
4 abc2 1
5 abc3 1
6 qwe 0
7 xyz1 2
8 xyz2 2
I have a set of ids like this: (1,4,7,8)
I want to show all the parent and child ids. Like this
id name parentID
1 abc 0
2 xyz 0
4 abc2 1
7 xyz1 2
8 xyz2 2
In my id list 2
is not present but id 2
is the parent of 7
and 8
so it is showing in the result set.
How to write query to show above result?