Hierarchical Data in MySQL

后端 未结 8 1625
南笙
南笙 2020-12-04 22:57

I\'ve got a sort of tree like thing going on in my MySQL database.

I have a database that has categories, and each category has a subcat. I\'m keeping all the catego

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 23:47

    But if I had like 10 categories under Toys, then I'd have to do this join and query 10 times. Is there a better way to handle this?

    Yes, there's a way of storing data called "nested sets". It's a bit harder to insert the data, but simple to select an entire, multi-level branch using a single select statement.

    Also, Celko has written a book about this subject, with a chapter about nested sets and other chapters about other methods.

提交回复
热议问题