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 8682657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:50:04+00:00 2026-06-12T21:50:04+00:00

I have a members table in which every site member is the unique id.

  • 0

I have a members table in which every site member is the unique id.
eg

id  firstname   secondname  emailaddress    country city    gender  

the second table is a friends table with the following structure

id  meid    friendid    date

what query would i use to get friend suggestions of a particular user based on mutual friends and sorted accordingly. before i was using php to loop thru and collect mutual friends but as the site grew, php started misbehaving and running out of memory.

This is the function i was using

//-----------------------------------------------    
function getFriendSuggestions($id)    
{
            $friendids=getFriendIdArray($id);  //returns list of your friends
            $networkids=getNetworkIdArray($id);//returns list of all members in your network(friends and their friends)
            $diff=array_merge(array(),array_diff($networkids,$friendids));
            $diff_mutual=array();
            $diff_mutual_total=array();
            for ($n=0;$n<count($diff);$n++)
            {
                $ff=getFriendIdArray($diff[$n]);
                $mf=array_merge(array(),array_intersect($ff,$friendids));
                $diff_mutual[]=$mf;
                $diff_mutual_total[]=count($mf);
            }
            $diff=array_merge(array(),$diff);
            $diff_mutual=array_merge(array(),$diff_mutual);
            $diff_mutual_total=array_merge(array(),$diff_mutual_total);    
            $w=$diff_mutual_total;
            arsort($w);
            $d=array();
            $dm=array();
            foreach ($w as $key => $value)
            {
                $d[]=$diff[$key];
                $dm[]=$diff_mutual[$key];
            }
            $cv=array($d,$dm);
            return $cv;
}
  • 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-06-12T21:50:05+00:00Added an answer on June 12, 2026 at 9:50 pm

    You want “friends of my friends, but who are not also my friends”.

    SELECT
      me.id                               AS member_id,
      their_friends.friendid              AS suggested_friend_id,
      COUNT(*)                            AS friends_in_common
    FROM
      members        AS me
    INNER JOIN
      friends_map    AS my_friends
        ON my_friends.meid = me.id
    INNER JOIN
      friends_map    AS their_friends
        ON their_friends.meid = my_friends.friendid
    LEFT JOIN
      friends_map    AS friends_with_me
        ON  friends_with_me.meid     = their_friends.friendid
        AND friends_with_me.friendid = me.id
    WHERE
      friends_with_me.meid IS NULL
    GROUP BY
      me.id,
      their_friends.friendid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple table called Member , which consists of the following:
I have a table which contains due dates for individual member records. Each row
I have a table which contains members signups and I would like to be
I am needing some help with SQL syntax. Say I have a members table,
I have a table that contains members names and a field with multiple ID
I have the following two table: -Groups- Id Name -Members- Id GroupId (Group.Id is
Hi Guys I currently have this table MEMBER **ID Position Latitude Longitute** 1 1
I have a custom DataContext with a Table member... Entry is defined as... [Table(Name=Entry)]
I have a User entity which represents a User table in my database. This
I have an entity called Project. Every project has group of members assigned to

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.