I am using a text box to process trees in SQL. This is easier than using left / right values.
Let's take an example from a MySQL article:
+-----------------------+ | name | +-----------------------+ | ELECTRONICS | | TELEVISIONS | | TUBE | | LCD | | PLASMA | | GAME CONSOLES | | PORTABLE ELECTRONICS | | MP3 PLAYERS | | FLASH | | CD PLAYERS | | 2 WAY RADIOS | | FRS | +-----------------------+
This will result in a table like this:
Id ParentId Lineage Name 1 null /1/ ELECTRONICS 2 1 /1/2/ TELEVISIONS 3 2 /1/2/3/ TUBE 4 2 /1/2/4/ LCD 5 2 /1/2/5/ PLASMA 6 6 /1/6/ GAME CONSOLES 7 1 /1/7/ PORTABLE ELECTRONICS 8 7 /1/7/8/ MP3 PLAYERS 9 8 /1/7/8/9/ FLASH 10 7 /1/7/10/ CD PLAYERS 11 1 /1/11/ 2 WAY RADIOS 12 11 /1/11/12/ FRS
Find all portable devices that you simply use Lineage from portable devices:
SELECT * FROM theTable WHERE Lineage LIKE '/1/7/%'
Minuses:
- You need to do UPDATE after each INSERT to add PK to Lineage
Sentence:
I usually add another column in which I put the path as text in (e.g. 'electronics/televisions/tube' )
source share