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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:21:20+00:00 2026-05-31T21:21:20+00:00

I have a set of ids in a table (column id), lets say from

  • 0

I have a set of ids in a table (column id), lets say from 1-10, I want to couple.

I have an existing set of completely randomly generated couples in a table (columns id1, id2).

I want to find the set of remaining couples on a single SQL statement.

It’s very easy for permutations, my problem is with combinations without repetition. That means when considering (id1,id2) == (id2,id1) or in other words I don’t know how to do to find a set which doesn’t include the existing couples with the order changed.

Any ideas?

E.g. If i have table myids

|id|
|1 |
|2 |
|3 |
|4 |
|5 |
|6 |
|7 |
|8 |
|9 |
|10|

and table mycouples

|id1|id2|
|1  |2  |
|9  |1  |
|7  |8  |

I should get 10*9 – 6 = 84 different couples with my statement, that is all posible permutations of 10 elements not including (id1=1,id2=2),(id1=2,id2=1),(id1=9,id2=1),(id1=1,id2=9),(id1=7,id2=8),(id1=8,id2=7).

  • 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-31T21:21:21+00:00Added an answer on May 31, 2026 at 9:21 pm
    SELECT
        m1.id AS id1
      , m2.id AS id2
    FROM myids AS m1
      JOIN myids AS m2
        ON m1.id <> m2.id
    WHERE NOT EXISTS
          ( SELECT *
            FROM mycouples AS c
            WHERE (c.id1, c.id2) = (m1.id, m2.id)
          )
      AND NOT EXISTS
          ( SELECT *
            FROM mycouples AS c
            WHERE (c.id2, c.id1) = (m1.id, m2.id)
          )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find items in common from the following_list column in a table
Say that I have a table with a bunch of records, which I want
I have a set of ids and names in an associative array and in
I have set up 2 servers which are linked. From my LOCAL SERVER, I
I have a table with about 1000 records and 2000 columns. What I want
I have a table with these columns: win, los, id ... I want to
I'm using SQL Server 2K8 and have a table used solely to generate ids
How can I set all values in OrderNumber column from 1 to n (when
I have a table that contains three user ID columns and an Active column
I have a table called profiles. There was a column in this table called

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.