SQL Self Join without double cross results
Hej!

Sorry I'm new to sql...
I'm searching for the solution since hours, but cat get it...
I hope someone can help me please!

My table:

    ID         name          value1      value2
    1          Meyer         20          _
    2          Schmitt       20          _
    3          Berger        _           20
    4          Chief         _           20


my query:

    SELECT A.ID, A.name AS nameA, B.name AS nameB, A.value1 
    FROM table AS A INNER JOIN table AS B
    ON A.value1 = B.value2

result:

    ID      nameA      nameB       value1
    1       Meyer      Berger      20
    1       Meyer      Chief       20
    2       Schmitt    Berger      20
    2       Schmitt    Chief       20  

THIS SHOULD IT LOOK LIKE:

    ID      nameA       nameB      value1
    1       Meyer       Berger     20
    2       Schmitt     Chief      20

I also tried the GROUP BY A.name: (wrong result...)

    ID       nameA      nameB     value1
    1        Meyer      Berger    20
    2        Schmitt    Berger    20

Looking forward to an answer!

Thank you & best regards
airfrank
     

SQL Self Join without double cross results
===

Hej!

Sorry I'm new to sql...
I'm searching for the solution since hours, but cat get it...
I hope someone can help me please!

My table:

    ID         name          value1      value2
    1          Meyer         20          _
    2          Schmitt       20          _
    3          Berger        _           20
    4          Chief         _           20


my query:

    SELECT A.ID, A.name AS nameA, B.name AS nameB, A.value1 
    FROM table AS A INNER JOIN table AS B
    ON A.value1 = B.value2

result:

    ID      nameA      nameB       value1
    1       Meyer      Berger      20
    1       Meyer      Chief       20
    2       Schmitt    Berger      20
    2       Schmitt    Chief       20  

THIS SHOULD IT LOOK LIKE:

    ID      nameA       nameB      value1
    1       Meyer       Berger     20
    2       Schmitt     Chief      20

I also tried the GROUP BY A.name: (wrong result...)

    ID       nameA      nameB     value1
    1        Meyer      Berger    20
    2        Schmitt    Berger    20

Looking forward to an answer!

Thank you & best regards
airfrank
     
