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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:46:43+00:00 2026-06-04T09:46:43+00:00

I need to select the users only when id_user_a and id_user_b match each other

  • 0

I need to select the users only when id_user_a and id_user_b match each other for a given user id.

users                  // SQL Statements: http://pastebin.com/w34qQv0g
id username
1  user1
2  user2
3  user3
4  user4

matches
id_user_a id_user_b
1         2
2         1
1         4
4         1

As you can see above, for a given user id 1, the id’s that match in both directions in matches table are id=2 and id=4. Because the first match with the second and vice-versa (1-2 and 2-1 :: 1-4 and 4-1).

And for a given id 4, just one id match in both directions (1-4 and 4-1) then just the id=1 match in both directions with the id 4. I want to select the id’s that matches in both directions for a given id. The concept is fairly clear, isn’t it ? but, How I can do that in a select statement ? Could anyone help me ? Thank you.

  • 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-04T09:46:44+00:00Added an answer on June 4, 2026 at 9:46 am

    For id 4:

    SELECT
    distinct m1.id_user_b
    FROM 
    MATCHES M1
    JOIN MATCHES M2 ON M1.ID_USER_A = M2.ID_USER_B AND M2.ID_USER_A = M1.ID_USER_B
    WHERE M1.ID_USER_A = 4
    

    And change 4 to parameter.

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

Sidebar

Related Questions

I have a feature matrix implemented with Silverlight's Grid where users need to select
I need to allow users to select an assembly in much the same way
I need to modify the open-source FCKeditor (not CKeditor) to allow users to select
I need to grant privileges to all users, I can do: GRANT select on
I have a simple application in which I need to let the user select
I need a way for user to select the portion of an image either
I need to pop up a quick dialog for the user to select one
i need this so that a logged in user id is used and only
I need an event/events that will do the following: After user selects text/DOM element,
how can i express in xpath a) need select elements which contains specified keyword.

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.