Team Table
x
Player (column)
A
B
C
Expected Output: with Two columns
Player vsPlayer
A B
B C
C A
How to write a sql query to get the exact output as Expected output mentioned above. Thanks in advance
Advertisement
Answer
The normal way to get combination (pairs) is to take all permutations, but where column 1 is less than column 2.
SELECT
l.player,
r.player
FROM
player l
INNER JOIN
player r
ON l.player < r.player
Demo : https://dbfiddle.uk/?rdbms=sqlserver_2019&fiddle=9ce7af3d0afe89c6434cc2800dfbd2ef