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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:09:26+00:00 2026-05-28T11:09:26+00:00

Assuming three tables which map a many to many relationship. People 1 Bob 2

  • 0

Assuming three tables which map a many to many relationship.

People
1 Bob
2 Mark
3 Peter
4 Tracy
5 Robert
6 ...

Favorite_Food
1 Icecream
2 Fish&Chips
3 Chocolate
4 Pizza

Pople_To_Favorite_Food
1, 2 # Bob likes Fish&Chips.
2, 2 # Mark likes Fish&Chips too.
4, 2
3, 3
3, 2
1, 1 # Bob likes Icevream.
3, 1
4, 1
5, 3

What is the recommended way to realize the following query:

  1. Selecting every favorite food of Bob.
  2. Then select every person, who shares at least one similar favorite food with Bob.
  3. List the names found.

So what I am looking for is some kind of back reference.

In this example it would have to result in: Bob likes Icecream and Fish&Chipy; Mark, Peter and Tracy like at least one food which Bob likes. So Mark, Peter and Tracy are listed.

I thought of doing something like

SELECT fk_people_id FROM [...join the tables here...] WHERE favorit_food_id IN (
SELECT fk_favorite_food_id [...join the tables here...])

Is this the way to go, or is there a more suitable concept I should be using?

Perhaps I should mention, that the table I want to query is really huge (Millions of entrys).

  • 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-28T11:09:26+00:00Added an answer on May 28, 2026 at 11:09 am

    Try this one –

    SELECT p2.* FROM People p1
      JOIN Pople_To_Favorite_Food pf1
        ON pf1.people_id = p1.people_id
      JOIN Favorite_Food f1
        ON f1.food_id = pf1.food_id
      JOIN Pople_To_Favorite_Food pf2
        ON pf2.food_id = f1.food_id
      JOIN People p2
        ON p2.people_id = pf2.people_id
    WHERE
      p1.name = 'Bob'
    GROUP BY
      p2.people_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables with a many to one relationship which represent lots and
Assuming I have three tables : TableA (key, value) TableB (key, value) TableC (key,
Assuming I have fonts installed which have the appropriate glyphs in them, is there
Say that I have three button elements in one parent div. Assuming that these
I have a CSV file, which contains three dates: '2010-07-01','2010-08-05','2010-09-04' When I try to
I have two tables with a parent/child relationship. I want to update the parent
Assuming I have 2 large tables with well over 10 Million Rows in each
Assuming there are 5 items in the settings file ( MySetting1 to MySetting5 ),
Assuming there are 5 inputs in web form <input name='the_same[]' value='different' /> <input name='the_same[]'
Should I be separating my js for each page assuming there is no overlap

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.