Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3361362
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:08:36+00:00 2026-05-18T03:08:36+00:00

If I wanted to create a site that allowed users to have 0 or

  • 0

If I wanted to create a site that allowed users to have 0 or more “friends”, how would I model such a relationship in a database? Would something this simple work:

Table Friends
- Id (PK)
- UserId (FK)
- FriendId (FK)

???

Would this allow me to later on do things like Facebook does (e.g. “3 of your friends knows this user, maybe you do too”)? Or something like 6-degrees-to-Kevin-Bacon?

EDIT 1:

Table Friends
- UserId (FK)
- FriendId (FK)
- Status ('Pending', 'Approved', 'Rejected', 'Blocked'?)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:08:37+00:00Added an answer on May 18, 2026 at 3:08 am

    This will work. Following are points to be noted:

    • Do you have something like friend confirmation. If yes, you will have to think on how to store ‘pending’
    • Indexing both UserId and FriendId. These are the values on which you will be joining the tables.
    • The unordered pair (UserId, FriendId) is contender for Primary key.
    • Suppose Uid_1 and Fid_1 are friends where Uid_1 != Fid_1 then does your Friends Table store (Fid_1, Uid_1) as well as (Uid_1, Fid_1).
    • How far in degrees of relationship are you going to search.

    Everytime you have to query for DOR(Degree of relationship) you will have to initialize a graph and run Shortest Path Algo (This is the least optimization I can think of). If your member-count rises to some kilos then how are you going to handle this?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building a mobile site and wanted to create a rotator that would work just
I wanted to have more than one controller and view for same object/model in
I want to create two div tags such that,they should be empty.I wanted to
I wanted to create a new property on a table in my model.. Basically
I wanted to create a very simple method that switches between views in a
If I wanted to create my own relational database with a modern language to
I wanted to create a function which would return the path of the current
I wanted to create a new WordPress page that is actually a link to
say if I wanted to give every user that registered on my site a
I'm new to codeigniter but I wanted to create an application like that of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.