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

  • Home
  • SEARCH
  • 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 4245742
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:52:50+00:00 2026-05-21T03:52:50+00:00

Guys back to being stuck with my sql layout on my tables, I just

  • 0

Guys back to being stuck with my sql layout on my tables, I just cant seem to understand how to do this.

I need Users to be able to be friends with other Users (Users are kept in the User table) im trying to create a “Friends” table so they can relate to one another.

I need the UserID stored along with FriendID, UserID is of the current user and FriendID is related to the UserID of the friend. ARGh so confusing.

Im getting lost even talking about it again, basically the way ive written my code i need the FriendID to relate to the UserID of the user table so i can find the person im after so I can display there credentials on the current “UserID” page but I also need some way to find out all the current UserIDs friends

UserID relates to all current friends (FriendID)
FriendID relates to a user in the User table (UserID)

So far all I have is this. How do I refrence FriendID back to UserID? If thats even the way.

enter image description here

  • 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-21T03:52:51+00:00Added an answer on May 21, 2026 at 3:52 am

    This is effectively a many-many relationship between UserA (Initiating User) and UserB (Target User) you need a IsFriendsWith table which associates the two, eg

    User
    -------------
    UserID [PK]
    Name
    etc,
    
    IsFriendsWith
    -------------
    InitiatingUserID [FK]
    TargetUserID [FK]
    

    So you can use this to find (for any initiating user) who they are friends with, and for any target user, who has made friends with them.

    EDIT – I am a SQL Server user, but the following query (or something close to it) should work in mysql in order to list all friends of user whose ID is defined in the parameter @UserID

    SELECT u2.Name FROM Users u1
        INNER JOIN IsFriendsWith ifw ON u1.UserID = ifw.InitiatingUserID
        INNER JOIN Users u2 ON u2.UserID = ifw.TargetUserID
        WHERE u1.UserID = @UserID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, back with not necessarily a true definition of a question but need some
A little stumped by this one so I'm hoping you guys can help. Looks
Hey guys back again with a whole new project for myself. In my earlier
Hey guys, i generally haven't used scaffolds, though i've been messing with Rails for
I am now working on an android app in which I need to display
I'm trying to build some CRM tools that send emails to my sales guys
I have a really weird WCF problem here... We're connecting to a crappy third-party
I feel so dumb right now: moveSequence look(COORD xyBeatle, fieldd &field); what could be
So I'm Bitmaping some heavy stuff to try bring down the [pre-render] and [render]

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.