A Query on MS SQL

Hi, 

i would like to get help writing a cross join query:

one table: Cities(City_name, X_coordinate, Y_coordinate)

the result should be all combinations without reverse column returns

SELECT * FROM [dbo].[Cities] as P1
Cross JOIN [dbo].[cities] as p2
where (p1.City_name != p2.City_name) and ???

for example if there are three Cities as A,B,C the result should be A->B, A->C, B->C (without the returns B->A, C->A, C->B)

thanks,

Ben

July 19th, 2015 10:30pm

Hi Ben_CH,

Visakh16's query would be good to acheve your requirement. I saw the where condition and the description said "without reverse column", then the INNER JOIN would lead to your goal, you don't have to use CROSS JOIN.

If you have any question, feel free to let me know.
Free Windows Admin Tool Kit Click here and download it now
July 20th, 2015 9:58pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics