categories table
categoies_id, parent_id
1, 0
2, 0
3, 0
4, 2
5, 2
6, 5
I wanted to find out the categories without children, for example, the above table will return (1, 3, 4, 6) for items without children.
I am thinking about
1) select parent_id from the table and create a set of parent_id.
2) select all the categories_id from the table too.
3) loop through categories id one by one, use the the membership set test on each categories id one by one, to check to see if each categories_id in the parent_id set, if not, it is a item without children.
Is there any better way to do the above work? simple function for that, rather than my 3 steps approach here. A some kind recursive function?
Thanks!