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 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

just a quick question guys, how can I simulate a tap on the back
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I
Guys, I am using SQL Server 2000 and executing the sp_columns stored procedure to
guys i have arrays in which i have to match this kind of text
guys I know this question is very basic but I've met in few publications
hey guys im really frustrated im looking for a way to retrieve back my
Ok, you guys were quick and helpful last time so I'm going back to
Hi guys I really need your help All I want to do is to
I can't seem to find any recent talk on the choice. Back in '06
I'm dealing specifically with C++, but this is really language-agnostic. Just to give some

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.