Sorry if this question has already been asked, but I didn't find it performing a search.
I have 2 tables (table_a
and table_b
), linked by a many/many relation.
The relation can be of two types, type_a
and type_b
.
I was wondering what was better between:
- Setting a
type
column in the relation table and during queries filter on this field - Creating 2 relations table, one for each type and apply no filter during queries
I can see advantage in both solutions, but I can't tell which one is generally used to solve this kind of problem
Best Answer
Adapted from here; see that for rationale.
For separated tables, each should look similar to this:
For the single table:
A third option is to put both types in a single table:
(
***
indicates the only deviation(s) from previous version.)Which is "best"? I don't know. And if you add
FOREIGN KEYs
, things get messier.