A while back I posted a different question regarding column order. While this question does not relate to column order, I was suggested to make my table differently from how I was making it.
Lets say I am selling 100 products. Some of these products are compatible with each other, some are not. Some have not been tested yet (I did not mention this part in my last question).
Would I be better off making a mySQL table like:
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 making the 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 failed to mention that there was also the “maybe” option (and not purely yes/no), meaning the third column would have to be added to the second table.
As an inexperienced mySQL’er, I ask, which table would be more efficient, more maintainable, and which would you recommend?
The second option is still better (even with the third column, which is no problem), because it allows you to easily add new product types without modifying the tables. (The technical term for this is that the schema is better”normalized”). This is much more maintainable. In addition, it means you can join across this table much more easily, or do queries to answer “which is the lowest-cost product which product 1 is compatible with” which would be very hard to do with the first table.