N * n table vs (n ^ 2) * 3 table in mysql

And back, I sent another question regarding the order of the columns. Although this question is not related to the order of the columns, I was asked to distinguish my table from how I did it.

Let's say I sell 100 products. Some of these products are compatible with each other, some are not. Some have not yet been tested (I did not mention this part in my last question).

It would be better to make a mySQL table, for example:

NAME         PRODUCT1     PRODUCT2     PRODUCT3     PRODUCT4 ....
product1     yes          no           maybe        yes
product2     maybe        yes          no           no
product3     maybe        yes          no           no
product4     maybe        yes          no           no
...

or make a table like:

FIRST       SECOND      COMPATIBLE?
Product1    Product1    Yes
Product1    Product2    Yes
Product1    Product3    No
Product1    Product4    Maybe
Product2    Product1    Maybe
Product2    Product2    Maybe
Product2    Product3    No
Product2    Product4    Maybe
Product3    Product1    Yes
Product3    Product2    Yes
Product3    Product3    No
Product3    Product4    Yes
Product4    Product1    Yes
Product4    Product2    No
Product4    Product3    No
Product4    Product4    Maybe

I was told that the second method would be better, but I did not mention that there is an option "maybe" (and not purely yes / no), that is, the third column should be added to the second table.

As an inexperienced mySQL'er, I ask: which table would be more efficient, convenient to maintain, and which would you recommend?

+3
3

( , ), . ( , "" ). . , , " , 1", .

+3

. - , . / , .

+2

- "-" . :

Product  DefinitelyCompatible  MaybeCompatible
----------------------------------------------
 1        '2, 3, 4'             '5'
 2        '1, 4'                '3'
 3        '1'                   '3, 4'
 4        '1, 2'                '3'
 5        ''                    '1'

, - , . , FIND_IN_SET() MySQL , , .

, ( Nx3), , , ( ).

- , ( a -compat- > b, then b -compat- > a), FIND_IN_SET() - - object (a b) ( , 23, 23 , , 4 5, , ). FIND_IN_SET() , , .

-1

Source: https://habr.com/ru/post/1756262/


All Articles