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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:44:29+00:00 2026-05-15T22:44:29+00:00

I am developing an app that needs to match people together. Each person can

  • 0

I am developing an app that needs to match people together. Each person can only match with one other person.. So, in the table below I am trying to make it so that values from user1 & user2 are unique across both fields:

CREATE TABLE `match_table` (
    `user1` int(11) NOT NULL,
    `user2` int(11) NOT NULL,
UNIQUE KEY `user2` (`user2`),
UNIQUE KEY `user1` (`user1`))

So for example the following INSERT statement should ignore rows 2 and 4. Or at a minimum I need to be able to flag those rows to be ignored. Note that line 5 is OK because of the fact that line 2 and 4 have been ignored.

INSERT IGNORE INTO match_table (user1, user2)
VALUES
    (1,2),
    (2,3),
    (4,5),
    (6,4),
    (3,6)

Is there any index that can accomplish this? .. Otherwise is there some UPDATE I could do after insertion that could flag the ones I want to ignore?

  • 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-15T22:44:29+00:00Added an answer on May 15, 2026 at 10:44 pm

    Assuming that the matching has no direction, you can use your existing table design but store the match both ways in the table:

    INSERT IGNORE INTO match_table (user1, user2)
    VALUES
    (1,2),
    (2,1),
    (2,3),
    (3,2),
    (4,5),
    (5,4),
    (6,4),
    (4,6),
    (3,6),
    (6,3)
    

    If you just fetch all rows you will got each matching twice. You can avoid this as follows:

    SELECT * FROM match_table WHERE user1 < user2
    1, 2
    3, 6
    4, 5
    

    One potential issue with this design is that it is possible to insert a row with a user who matches himself.

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

Sidebar

Related Questions

I'm developing an iPad app that needs read-only access to an Oracle database. Is
When developing an app that will listen on a TCP/IP port, how should one
I'm developing a Mac App in Java that logs into any one of our
I am developing an app that needs to send text messages, so I have
I'm developing an app that needs to cache some images from the web the
We are developing an iphone app that needs to process audio data in real
I am developing an app that needs to play music while on the phone.
I'm developing an app that needs a real boost from multi-threading features like NSOperation
it's the first time I'm developing an app that needs to be localized into
I'm developing a web app that needs to use HTML5 websockets. Is there any

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.