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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:14:03+00:00 2026-06-08T07:14:03+00:00

I have a relationship table in my database that has four values AKA… id,

  • 0

I have a relationship table in my database that has four values AKA…

id, int, primary, auto-incriment 
mem1, int
mem2, int
type, enum('a','b')

I also have another table that has the members id, username, firstname, and lastname

I want to click a button and get the relationships between the two people without duplicates.
Here is the query I have so far…

SELECT 
    myMembers.id AS id, 
    myMembers.username AS username, 
    myMembers.firstname AS firstname,
    myMembers.lastname AS lastname 
FROM myMembers 
INNER JOIN memberRelations 
    ON memberRelations.mem2=myMembers.id
WHERE memberRelations.mem1='$id' OR memberRelations.mem2='$id' ORDER BY myMembers.username 
ASC

The problem here is that on some users it gives me the correct values, but on others it gives me the profile user and not the other member relationship. I suspect this has to do with the ON portion of the query, but truthfully I am lost! Is there a better way to accomplish my goal? Or can I just correct something in my query? Any help would be greatly appreciated. Thanks!

  • 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-08T07:14:06+00:00Added an answer on June 8, 2026 at 7:14 am

    Based on your question, I think you want the following which selects both members of the relationship:

    SELECT
        R.type,
        M1.id AS id1, 
        M1.username AS username1, 
        M1.firstname AS firstname1,
        M1.lastname AS lastname1,
        M2.id AS id1, 
        M2.username AS username2, 
        M2.firstname AS firstname2,
        M2.lastname AS lastname2
    FROM memberRelations AS R
           INNER JOIN myMembers AS M1 ON R.mem1=M1.id
           INNER JOIN myMembers AS M2 ON R.mem2=M2.id
    WHERE R.mem1='$id' OR R.mem2='$id'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a database that already has a users table COLUMNS: userID - int
How should columns in a database table that have a PK/FK relationship be named?
I have a table in my SQLServer 2000 database that has in my opinion
I have a table Location that has a foreign key relationship to a Site.
I have a table that has a one to many relationship with itself. Each
I have a database that has a table of Ingredients I and a table
i have a many to many table relationship that involves 2 logical tables. Record
I have an table Article that is in relationship with Steps (OneToMany) and Steps
I have a table which has employee relationship defined within itself. i.e. EmpID Name
I have a Product entity that has a foreign key relationship to Manufacturer. I

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.