SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Help with SQL query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jbon
Starting Member

Sweden
20 Posts

Posted - 09/12/2013 :  08:27:16  Show Profile  Reply with Quote
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

Belarus
172 Posts

Posted - 09/12/2013 :  08:52:07  Show Profile  Reply with Quote
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

Edited by - sigmas on 09/12/2013 09:00:06
Go to Top of Page

jbon
Starting Member

Sweden
20 Posts

Posted - 09/12/2013 :  10:33:26  Show Profile  Reply with Quote
Thanks Sigmas,
your input solved my problem.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000