I’m searching for the solution since hours, but cat get it.
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 look like:
ID nameA nameB value1
1 Meyer Berger 20
2 Schmitt Chief 20
How can I get this result?
I also tried the GROUP BY A.name, but get the wrong result:
ID nameA nameB value1
1 Meyer Berger 20
2 Schmitt Berger 20
You have not specified DBMS. This is tested in SQL Server:
Testable sample: