I found out two possible solutions for implementing the database structure for social networking sites like Facebook.
1.: Creating a 'Relationships' table and inserting every friendship into it. For example: user A adds B as friend (A-B), then the logic puts (A-B) and (B-A) into the 'Relationships' table. Then it indexes the first attribute.
2.: Creating a unique table for all the users containing friends. Most databases work with nearly 2 billion unique tables, so it won't be a problem; however, the database size will be nearly 300 times bigger (expecting 300 friends average per user). In this scenario, querying friends would not be a problem (as simple as SELECT * FROM)
Any ideas? Am I wrong somewhere? Thanks all.