I'm just finding out how to implement the Nested Set Model but nonetheless have confusion having a certain facet of it including products that might be a part of multiple groups. Because of the example below which was drawn from HERE and mirrors a number of other good examples I know of...

Hierarchical Data: Numbered Tree


How can you avoid duplication within the DB whenever you add Apples being that they are multi-colored (i.e. Red-colored, Yellow, Eco-friendly)?

You don't avoid duplications and also the apple (or perhaps a mention of apple) is going to be placed two times inside your tree otherwise it will not be considered a tree but instead a graph. Your real question is equally relevant should you develop a... Swing JTree or perhaps an HTML tree ).

The nested set model is simply a competent method to push and traverse a tree structure inside a relational DB.It's not an information structure itself. It's popular among MySQL customers since MySQL lacks functionality for processing tree structures (e.g. such as the one that Oracle provides).


Nested set model is really a structure for 1:N (one-to-many) associations, you need to use M:N (many to a lot of) relationship (many products might have apple as parent, but could have several parent).

See this article


But you should know, that hierarchical M:N associations could possibly get quite complex really fast!