Jackanap3s
Jackanap3s

Reputation: 59

Database modelling for 2 many-to-many relations that have their own one to many relation

enter image description here

With reference to the attachment, data has a many to many relationship with both entities. What would be the right thing to do?

To add more context, each data entry can have 0, 1, 2, ..., N categories, where N is the number of categories in the category table. For each category an entry has, it can have 0, 1, 2, ..., N_c sub categories associated with it, where N_c is the number of sub categories a category has.

I have thought about making one joining table between the data and sub category since each sub category will also tell me the category, but this is susceptible to having a data entry that has a category but no sub category - which is possible.

Is having 2 joining tables the best thing to do? Would you consider this approach to have some form of data redundancy since we some of the categories if we have sub categories

Upvotes: 0

Views: 20

Answers (1)

Jackanap3s
Jackanap3s

Reputation: 59

After some more thinking, I think this is the best solution. enter image description here

This eliminates a data entry from having sub categorisations without a main categorisation.

Upvotes: 0

Related Questions