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

  • Home
  • SEARCH
  • 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 6065013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:20:36+00:00 2026-05-23T09:20:36+00:00

I have database table with the following structure, that is used to match people

  • 0

I have database table with the following structure, that is used to match people at a dating event:

ID | EVENT | USERS_ID | MATCH_ID | GENDER
1 | 27 | 54 | 1245 | Female
2 | 27 | 54 | 21 | Female
3 | 27 | 21 | 45 | Male
4 | 27 | 21 | 54 | Male

I am trying to write my query that will give me my matches.
For example, from the data above, user 54 matches user 21 because 54 picked 21 and 21 picked 54.

I need to pass as an input a USER_ID and the EVENT and get a list of the MATCH_ID that match that user.
So,

SELECT match_id FROM……. WHERE users_id = 54 AND event = 27

I also need to know which users DIDN’T get any matches. This would be a separate query. From the example above, user 45 had no mutual matches.

I’ve been fighting with this one for a while. Any ideas on this would be great.

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-05-23T09:20:36+00:00Added an answer on May 23, 2026 at 9:20 am

    Not tested, but I think this should do it for you:

    SELECT t2.users_id FROM 
    tbl t1
    INNER JOIN tbl t2
    ON t1.users_id = t2.match_id AND t1.match_id = t2.users_id
    WHERE t2.event = 27
    AND t1.users_id = 54;
    

    Also, for finding all the users who don’t have any matches, this would probably work:

    SELECT t1.match_id
    FROM
    tbl t1
    LEFT JOIN 
    tbl t2
    ON t1.match_id = t2.users_id
    WHERE t2.id IS NULL;
    

    The general principle here though, is to join the table to itself, and find matches that way.

    EDIT: Made some corrections, feel pretty confident this should work well for you.

    EDIT 2: Here is the final correction, which I believe should pull this all together for you.

    SELECT * FROM
    event_matches t1
    INNER JOIN event_matches t2
    ON t1.users_id = t2.matches AND t1.matches = t2.users_id AND t1.event_id = t2.event_id
    WHERE t2.event_id = 45
    AND t1.users_id = 1239;

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

Sidebar

Related Questions

I have no control over database schema and have the following (simplified) table structure:
I have a SQL database that has the following table: Table: PhoneRecords -------------- ID(identity
I have a database/table in SQLITE using the following structure CREATE TABLE milestones (
I have the following table structure in my database: create table Encargado( ID int
I have a MySQL database with the following table structure: TransactionType : Transaction_Amount, Transaction_ID,
I have a table in database which has following structure(data) : +--------------------------+ Organization +--------------------------+
I have a database-table with the following structure: id1 | id2 | weight Now
I have a database table with the following structure - Week_End Sales 2009-11-01 43223.43
I have a SQL database table with the following structure: create table category_value (
I have a database schema that includes the following tables: People Organisations RelationshipTypes What

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.