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 Answer