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 2012 Forums
 Transact-SQL (2012)
 Help with SQL query

Author  Topic 

jbon
Starting Member

20 Posts

Posted - 2013-09-12 : 08:27:16
Hi,
I have a table (simplified) ctry_zone with two columns (ctry, zone)

ctry_zone (ctry, zone):
SE SE1
SE SE2
SE SE3
SE SE4
EE EE1
EE EE2
EE EE3

I want to create a query that returna result as below

(zone_from, zone_to):
SE1 EE1
SE1 EE2
SE1 EE3
SE2 EE1
SE2 EE2
SE2 EE3
... ...
SE4 EE3

Any kind of help/support/guidance is highly appreciated.

Thanks in advance!

sigmas
Posting Yak Master

172 Posts

Posted - 2013-09-12 : 08:52:07
use self join like this:

select a.zone as zone_from, b.zone as zone_to
from ctry_zone a
join ctry_zone b
on a.ctry > b.ctry
Go to Top of Page

jbon
Starting Member

20 Posts

Posted - 2013-09-12 : 10:33:26
Thanks Sigmas,
your input solved my problem.
Go to Top of Page
   

- Advertisement -