I have a table country with single column that has the below values
India
Pakistan
Australia
Srilanka
My result should be like this
India vs Pakistan
India vs Australia
India vs Srilanka
Pakistan vs Srilanka
Pakistan vs Australia
Australia vs Srilanka
How do we achieve this with self join?
Tried with self join but unable to know how to retrieve first value and second value from column
3条答案
按热度按时间eblbsuwk1#
Use the self join with a condition so that a country cannot play against itself:
fiddle
More combinations can be achieved with
<>
in the condition:fiddle
xriantvc2#
I would suggest adding another column id to your table so you can get the correct result, for example:
and your query can be:
Result
Full example here
h7wcgrx33#
You can use
CROSS JOIN
, andWHERE c1.name < c2.name
:Demo here