fuschia
fuschia

Reputation: 283

MySQL Making pair of values from one column based on similarity on other column

I'll apologize in advance because this has likely been answered somewhere but I could not seem to be able to find the answer I need, and can't manage to adapt other code I have found to my needs.

I have a table as follows:

   NAME          PAPER
    A             10
    B             20
    C             10
    D             30
    A             40
    C             20
    E             30
    F             40
    G             10

And I want to produce a pair of value in the name, if they have the same paper. And both of the columns can have duplicate number .

For example, the result of the above would be:

   NAME          NAME
    A             C
    B             C
    D             E
    A             F
    A             G
    B             G 

Is there any function in mysql that can do this?

Upvotes: 0

Views: 92

Answers (1)

Horaciux
Horaciux

Reputation: 6477

select a.name, b.name
from myTable a 
inner join myTtable b
on a.paper=b.paper and a.name<b.name

SQL FIDDLE TEST

Results

A   C
B   C
D   E
A   F
A   G
C   G

Upvotes: 2

Related Questions