mysql - many to many relationship relational db -


i know technically mysql doesn't support many many. should create bridge table. in case still confused that.

how 2 tables (or more) when many users can have many friends? think of social network app.

user ===== id name  friend ===== id name 

i'm confused , don't know how link them, because in friend table id can users' id.

its best practicate make 3rd "mapping" table.

user ===== id name  m2m_user_friend ===== user_id friend_user_id 

both user_id , user_friend_id foreign keys user table.

this allows efficient querys "give me friends of person id=17" , also, if friend-connections one-directional (e.g. friendship requests), can things other way around "show me people are/want friends id=17".

social networks use called graph database, likely. relational databases great - unless need scale up. gets though @ point split data on 10,000s of machines tradional databases mysql.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -