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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:50:53+00:00 2026-05-31T06:50:53+00:00

Have 4 relationship tables in my database and want to join them to get

  • 0

Have 4 relationship tables in my database and want to join them to get the total value… for instance i have friends, family, following and acquaintances and want to join these to get an “ALL” value.

The table formats are as such:

Friends

id follower following
---------------------
1     2      3
2     4      5

Family

id follower following
---------------------
1     5      6
2     7      8

Following

id follower following
---------------------
1     9      10
2     11     12

Acquaintances

id follower following
---------------------
1     13     14
2     15     16

Is the correct query to join all 4 tables…

SELECT following
FROM   friends
       INNER JOIN family ON friends.following=family.following
       INNER JOIN following ON friends.following=following.following
       INNER JOIN acquaintances ON friends.following=acquaintances.following
WHERE  follower='id'

Basically I want to join and retrieve the “following” value from all four tables where id= my id

  • 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-31T06:50:55+00:00Added an answer on May 31, 2026 at 6:50 am

    Your current query will only list a result if all tables have a link with your friends table. I believe you are more looking for something like this

    SELECT following
    FROM   friends
    WHERE  follower='id'
    UNION ALL 
    SELECT following
    FROM   family 
    WHERE  follower='id'
    UNION ALL 
    SELECT following
    FROM   following
    WHERE  follower='id'
    UNION ALL 
    SELECT following
    FROM   acquaintances 
    WHERE  follower='id'
    

    or a bit nicer to read and easier to adjust at the cost of some performance

    SELECT following 
    FROM   (
            SELECT following, follower FROM friends
            UNION ALL SELECT following, follower FROM family 
            UNION ALL SELECT following, follower FROM following
            UNION ALL SELECT following, follower FROM acquaintances 
           ) AS f
    WHERE  follower='id'
    

    UNION

    UNION is used to combine the result from multiple SELECT statements
    into a single result set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a many-to-many relationship between two tables, let's say Friends and Foods. If
i have a database with 3 tables in a many-to-many relationship. one is the
I have bands , genres and bands_genres database tables with a HABTM relationship I
I have a many to many (with a join table) relationship in my database
I have a database schema that includes the following tables: People Organisations RelationshipTypes What
I have a secondhand sale car database and four tables with relationships. Same column
Background In a PostgreSQL 9.0 database, there are various tables that have many-to-many relationships.
Is it possible to have a many to many relationship between two tables, and
I've just gone blank. I have a many to many relationship with three tables.
I have two tables with primary foreign key relationship. The table in foreign key

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.