Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comple x Query

Status
Not open for further replies.

amerbaig

IS-IT--Management
Sep 4, 2001
58
0
0
CA
I have following two tables

Table1
refcode CityCode
1240 2240
1340 2340
1440 2440

Table2
CityCode1 CityCode2 Distance
2240 2340 100
2340 2440 200

I want to get output like this

refcode1 RefCode2 Distance
1240 1340 100
1340 1440 200


How should I write SQL?

Regards
Amer
 
Try this one:

select refcode1, refcode2, dist1
from (select a.refcode refcode1, distance dist1
from table1 a, table2 b
where a.citycode = b.citycode1) a,
(select a.refcode refcode2, distance dist2
from table1 a, table2 b
where a.citycode = b.citycode2) b
where a.dist1 = b.dist2;
 
try this also..........

select b.refcode refcode1, c.refcode refcode2, a.distance
from table2 a, table1 b, table1 c
where a.citycode1 = b.citycode
and a.citycode2 = c.citycode ;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top