SQL Help requirred

Database
Enthusiast

SQL Help requirred

Hi,

 

I have a table as below:

 

Country_Name
India
Pakistan
Srilanka

 

And I want to have a output like below:

Country_NameCountry_Name
IndiaPakistan
PakistanSrilanka
SrilankaIndia

 

Where I dont want to have the rows such as Pakistan-India as India-Pakistan is already there.

 

Thanks in advance,

 


Accepted Solutions
Junior Contributor

Re: SQL Help requirred

You need a non-equi self-join:

SELECT t1.Country_Name, t2.Country_Name
FROM mytable AS t1 JOIN mytable AS t2
ON t1.Country_Name < t2.Country_Name
1 ACCEPTED SOLUTION
2 REPLIES
Junior Contributor

Re: SQL Help requirred

You need a non-equi self-join:

SELECT t1.Country_Name, t2.Country_Name
FROM mytable AS t1 JOIN mytable AS t2
ON t1.Country_Name < t2.Country_Name
Enthusiast

Re: SQL Help requirred

Thanks Dnoeth.