0

I want to have all attributes related to a category or it's parents (recursively). This is the database structure.

Categories
--------------------
id
parent_id

Attributes
--------------------
id
attribute_set_id


Attribute_Groups
----------------------------
id


Categories_Attribute_Groups
-----------------------------
category_id
attribute_group_id


Categories_Additional_Attributes
-----------------------------
category_id
attribute_id

An example:

Categories:

id     |    name    |   parent_id
_______|____________|______________
1      |Root        | null
2      |Parent      | 1
3      |Child       | 2

There are some attributes and attribute groups that are related to parent, and the child has one attribute (with Categories_Additional_Attributes).

I want an efficient way to get all the attributes that the child and it's parent and the root has.

Community
  • 1
  • 1
  • Please be aware that `Categories_Attribute_Groups` gives me the group of attributes name, not the attributes themselves. – Alireza Mirsepassi Jun 20 '18 at 15:03
  • 1
    Please have a look at e.g. [How to create a MySQL hierarchical recursive query](https://stackoverflow.com/q/20215744/6248528) (or any other question containing "recursive" and "mysql", they are usually all about that same problem you have). Try to adept it to your situation, and if you fail, share your attempts, so we can fix it/help you. Your problem is a two-parter: the hierarchy, and the joining to your attributes/groups the categories contain. Be precise as to which part you have a problem with. Also some sample data/sample output for your complex attribute structure would probably help. – Solarflare Jun 20 '18 at 18:09
  • Hi. This is a faq. Please always google many clear, concise & specific versions/phrasings of your question/problem/goal with & without your particular strings/names & read many answers. Add relevant keywords you discover to your searches. If you don't find an answer then post, using use one variant search for your title & keywords for your tags. PS Please edit clarifications into posts, not comments. – philipxy Jun 21 '18 at 05:04
  • Possible duplicate of [How to create a MySQL hierarchical recursive query](https://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query) – philipxy Jun 21 '18 at 05:05

0 Answers0