Subject AW: [firebird-support] nested set
Author checkmail

… Hello,

 

it works, please tell if I can make it better ;)

 

with mkat as (

SELECT node.id

FROM tmatkat AS node,

tmatkat AS parent

WHERE node.lft BETWEEN parent.lft AND parent.rgt

AND parent.id = 190

ORDER BY parent.lft

)

select d.bezeichnung,  d.bestellnr

 

from tmaterial d

      join tmaterial_kat e on d.id = e.matid

      join mkat f on e.katid = f.id

      group by d.bezeichnung, d.bestellnr

 

Von: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] Im Auftrag von checkmail
Gesendet: Freitag, 14. Februar 2014 09:04
An: firebird-support@yahoogroups.com
Betreff: [firebird-support] nested set

 

 

Hello,

 

the following sql statement returns me all subcategories of material, starting with the category id 190 and returns it.

 

SELECT node.bez

FROM tmatkat AS node,

tmatkat AS parent

WHERE node.lft BETWEEN parent.lft+1 AND parent.rgt

AND parent.id = 190

ORDER BY parent.lft;

 

(at the time it returns me the name, in my case I will get the ID of the category)

 

Second, I have a table where I can set one or more category to an piece:

 

ID primary key

ID_Material

ID Category (includes left and right nested set)

 

Now I would get all the Material from the third table tmaterial, where the category matches.

 

For example:

 

The first select returns me categories 22, 32 and 56

 

Material ID 23 has assigned the Category IDs 22, 56 and 123

Material ID 24 has assigned the Category 56

Material ID 25 has assigned the Category 234

 

Now I should get the Material IDs 23 and 24 for one time (ID 23 not two times)

 

Can anybody helps?

 

Thank you and best regards

 

Olaf