Storing an array in a MySQL database

Go To StackoverFlow.com

0

Is it possible to have a table with the columns user_id and friends and store the user id's of all of the users a user is friends with? Or is it better to have a row for every "relationship" in the friends table? What is more practical?

2012-04-04 20:56
by user1174762


4

It depends a little on how you intend to use it, but usually, yes, you'd want a row for each relationship for easier querying of those individual relationships ("how many people are friends with Bob", "how many friends does Jane have total", etc.).

2012-04-04 20:57
by ceejayoz
Agree. In order to see "Who is friends with Jane?" and all friends were stored in a serialized array or text string, you would have to evaluate your entire database. With individual relationships, you can just query specifically for that relationship - Blake 2012-04-04 21:02
Ads