PDA

View Full Version : nested query within a table



tutunmayan
10 Dec 2008, 06:16 AM
Hi, I have a product groups table that has a hierarchical structure that also keeps subgroup info (by parent).

This is my table (mysql)


id_group -- group_name -- parent --
___________________________________
1 -- Phones -- 0 --
2 -- Has cam -- 1 --
3 -- No cam -- 1 --
4 -- Has Flash -- 2 --
5 -- No Flash -- 2 --
6 -- Many Other-- 0 --
7 -- Many Other-- 0 --
8 -- Many Other-- 0 --


Is it posible to select all product groups related to Phones with one query?
I.e all products whose master parent is somehow "Phones" (products with id 2,3,4 and 5)

If not posible what is the best way to do this.

Thanks