There are two tables. Table with these goods and a table brands. These two tables are related to each other through a third table.
You have one item may have several brands?
I understand the need to make a table of ratios where the two fields id_товара and id_его analog
For example item with ID 1 there are three analogue - turns out one item three entries. In this analogue the analogue product with the ID 1, and the remaining two goods. Already 6 records. In General, something I do not like the decision.
Overall, this is quite normal practice, at least from the point of view of logic. For example, "light And" logically can be replaced by "light B", but reverse substitution may not be appropriate for some indications. Also, in this scenario, You will be able to sort the output by a unique degree of "recommendation rates" applying to each product and so on. But this approach definitely has shortcomings, in particular, this data redundancy, additional movements to add unparalleled in every product, extra disk space, bloating the database and so on.
If all the goods among themselves are absolute counterparts of each other, there is an alternative approach. It is that you create a group of counterparts, for example, in table analog_groups
, every record where a = 1 group counterparts. Further, You indicate in the item, which group it belongs to analogues, it is possible to make both the group ID and its title (or any other parameter that You add) or option id_группы_аналогов any other product that is this group already included.
Features of this approach:
a) the Lack of data redundancy
b) All the goods in one group of analogues will always be analogues to all other products in this group
C) We will not need to do many of the same movements, constantly perelinkovat similar products from each other
g) Save the disk space and database size remains the same
d) We are unable to put a sort or the priorities of the output analogues for each individual product without harsh crutches