Mirrored Data [Duplicate data]

I have the weirdest thing to sort out...

I have a table with IndexA and IndexB

In the table EVERY IndexA,IndexB match is mirrored.

For example:

      IndexA          IndexB
         112              42
          42             112
         112              15
          15             112

112, 42, 15 are "Matched" (one group). I need to create a random group index and put 112, 42, 15 in it.

These sets do terminate, they don't all wind up being part of the same group.

Example: Down the line you'll find

      IndexA          IndexB
         27             13
         13             27

And there are no pairs matching 112, 42 or 15 to either 27 or 13. I know because when I query where IndexA = 27 or IndexB = 27 only these 2 rows show up.

This is the stuff nightmares are made of...

Any help would be appreciated.