Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 t-sql statement needed..

Author  Topic 

nagarjuna_a2006
Starting Member

16 Posts

Posted - 2014-11-02 : 08:17:22
I have below data
SlNo Country
1 India
2 Pakistan
3 Srilanka

i need a query that it should results Each country should play with other country

expected o/p:

Country Country
India Pakistan
India Srilanka
Srilanka Pakistan

output of the result set order is not important, i need the logic how to write it.

Thanks in advance


Regards,
Nagarjuna

mole999
Starting Member

49 Posts

Posted - 2014-11-02 : 08:59:03
isn't that full outer join country on country, which produces all options

http://stackoverflow.com/questions/13997365/sql-joins-as-venn-diagram

Mole
Go to Top of Page

nagarjuna_a2006
Starting Member

16 Posts

Posted - 2014-11-02 : 09:02:29
if i user full outer join , result is showing as below

Country Country
India India
Pakistan Pakistan
Srilanka Srilanka

please suggest..

Regards,
Nagarjuna
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2014-11-03 : 07:44:59
[code]
SELECT T1.Country, T2.Country
FROM YourTable T1
CROSS JOIN YourTable T2
WHERE T1.SlNo < T2.SlNo;


SELECT T1.Country, T2.Country
FROM YourTable T1
JOIN YourTable T2
ON T1.SlNo < T2.SlNo;
-- etc
[/code]
Go to Top of Page

nagarjuna_a2006
Starting Member

16 Posts

Posted - 2014-11-03 : 23:42:56
Excellent,
Thank you so much.

Regards,
Nagarjuna
Go to Top of Page
   

- Advertisement -