I have a self-referential table that contains parents and childen in the same table. Here is a sample of my table:
I need query that counts the number of children each parent has. It doesn't have to count the grandchildren. So the data above would return the following:
Thanks for your help.
Code:
service_codes
------------------
[b]uid[/b] [b]parent_id[/b] [b]descrip[/b]
14 NULL Basic Needs
15 14 Food
17 15 Emergency Food
59 14 Housing/Shelter
72 NULL Education
265 NULL Consumers
266 265 Consumer Assistance
I need query that counts the number of children each parent has. It doesn't have to count the grandchildren. So the data above would return the following:
Code:
[b]uid[/b] [b]Descrip[/b] [b]Children[/b]
14 Basic Needs 2
72 Education 0
265 Consumers 1
Thanks for your help.