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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:32:14+00:00 2026-06-18T00:32:14+00:00

I’m trying to fetch mutual friends. I have a table structured like this: `friends`

  • 0

I’m trying to fetch mutual friends.

I have a table structured like this:

 `friends` (   
    `inviter`  int(11) NOT NULL,   
    `accepter`  int(11) NOT NULL,   
    `time` datetime NOT NULL,)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci;

My load_my_friends(##MY ID##); query is like this:

SELECT  p.id , p.name,p.lastname,p.thumb
FROM  friends AS f
RIGHT JOIN  profiles AS p ON ( f.accepter = p.id OR f.inviter = p.id ) 
WHERE  f.inviter = ##MY ID##
OR  f.accepter = ##MY ID##
LIMIT 0 , 5000

Could you tell me how I can fetch the mutual friends data.

Note: I’m not using any social-network script like JCOW,Social Engine etc.


Edit for @2

In the database I have user1,user2,user3,user4,user5..userX

  • user1’s friends are: 2,3,6,7,8
  • user2’s friends are: 1,3,4,5,7,8

I want a query which can fetch these results:

     | id  | name |lastname| thumb
    1|  3  |raheel|shan    | /img01.jpg
    2|  7  | arqu |x       | /img02.jpg
    3|  8  |abcdef|hijklmno| /img06.jpg
  • 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-18T00:32:15+00:00Added an answer on June 18, 2026 at 12:32 am

    A query that’s probably easy to understand is the following:

    SELECT p.* 
    FROM 
        (
           -- all friends of User A
           SELECT accepter AS friend_id FROM friends WHERE inviter IN (##User_A_ID##)
           UNION
           SELECT inviter AS friend_id FROM friends WHERE accepter IN (##User_A_ID##)
        ) AS t1
        -- intersect with
        JOIN
        (
           -- all friends of User B
           SELECT accepter AS friend_id FROM friends WHERE inviter IN (##User_B_ID##)
           UNION
           SELECT inviter AS friend_id FROM friends WHERE accepter IN (##User_B_ID##)
        ) AS t2
        ON t1.friend_id = t2.friend_id
    
        JOIN profiles p on p.id=t1.friend_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I am trying to loop through a bunch of documents I have to put

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.