mysql optimize tables

mysql, optimization

Solution

No Dear,

you just need one single table for make friend relationship. structure is following i have used

id (primary key) | my_id( integer logged user id ) | friend_id ( integer user id of another user he will receive friend request from logged user)

like we have two users in our users table then we have two entries for both user to make relation with each other

id | name | age
1  | vipan | 12
2  | karan | 12

then entry should be

id | my_id | friend_id
 1     1        2
 2     2        1

Please don't vote down in any case but i have use this table structure in my site and this is same structure used in joomsocial this is best table structure i think so i use it and please don't use comma separated values in table they will make problem in joins and relationship in some cases

Please see 4 number comment in this following link of post

Separate comma separated values from mysql table

Problem

I want to create a friends system (something like in facebook). I want to save relationship data in MySql, but I do not know which way is better: To save everysingle relationship as a single entry, such as: ``` id | people1 | people2 1 | john | maria 2 | john | fred 3 | maria | fred ``` (there i declare relationships between all of these 3 peoples) To save everyone name and list his friends: ``` id | people | friends 1 | fred | mary, john 2 | mary | john, fred 3 | john | fred, mary ``` Or maybe there is better way?

Original source

Related problems