vendredi 31 juillet 2015

SQL query for parent child with no relationship

I need urgent help regarding a query that I want to create. For instance, let's say I have this table:

Description Level Is_Active

---------------------------------------------------- (1)Metallic industry products 1 1 (2)+ Various metal products 2 1 (3)++ Other metal products 3 1 (1)Rubber and plastic products 1 1 (2)+ Rubber products 2 1 (2)+ Other rubber products 2 1 (3)++ Other product types 3 1

where level specifies the relationship. The records in the table are set to reproduce a tree structure. What I'm trying to do is a query which selects all the parents with children from this table that are active. If, for instance, the Is_Active column for Metallic industry products is set to 0, I don't want to display it and it's children (arious metal products and other metal products). The same for Various metal products, if it's not active, don't display it and it's children. I tried joining with the same table or using the WITH function but saddly I can't find a solution.

Aucun commentaire:

Enregistrer un commentaire