I'm trying to make a database of users for a website that will store correlation values between all the users. What I mean by this is that for every pair of users, there is a stored value of correlation between the two users.
The correlation values will be calculated by PHP using a correlation algorithm. My question is what is the most correct way to store them in a MySQL database? I realize I could make a table like this:
---------------------------------
| user1 | user2 | user3 | etc... |
-----------------------------------------
| user1 | #val | #val | #val | #val |
-----------------------------------------
| user2 | #val | #val | #val | #val |
-----------------------------------------
| user3 | #val | #val | #val | #val |
etcetera. But I don't like this method because
- It stores every value twice; for example the correlation between user1 and user3 is stored in row 1 column 3 as well as row 3 column 1.
- I use prepared statements, which means I can't select columns named after user IDs unless I concatenate the user ID into the SQL statement, which is obviously not ideal.
What are my alternatives? If this can be done in MySQL well, how do I go about it?
If this can't be done well in MySQL, are there any other database types I should try to learn? For example, I realize a graph database system may work well for this, but I don't want to spend time learning how to use a graph database if this can be done in MySQL.