A little background so you understand what I’m trying to do. I am making a page that takes two user input products and checks to see if they are compatible with one another. This is an n+1*n mySQL table because there are n products.
The table looks like
name a b c d e
a
b
c
d
e
I already know that every product is compatible with itself, so to save time, is there a query that will automatically fill the table out so that I can get
name a b c d e
a 1
b 1
c 1
d 1
e 1
Thanks
I forgot to mention, each product can be compatible with an several other products. The diagonal I’m putting in is just a starting point.
Not a direct answer to your question but I felt I had to mention it…
If possible you should consider changing your design to the following:
If you insert rows for both (a, b) and (b, a) then your query is simple:
Also, when you add new products you won’t have to change your database schema.