If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > SQL Statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-12, 22:24
Tharangi Tharangi is offline
Registered User
 
Join Date: Jan 2012
Posts: 10
Red face SQL Statement

Hi All,

I have two tables look like following,

TABLE 01 has three columns flightNO,dest_airport_code,Origin_airport_code
TABLE 02 has two columns airport_code,airport_name

I want to retrive flightNO,dest_airport_code,airport_name,Origin_air port_code,airport_name

airport_name after the dest_airport_code is the relavent airport name and airport_name after the origin_airport_code means the relavent origin airport name.How can I retrive these columns.

please help me.
Reply With Quote
  #2 (permalink)  
Old 02-09-12, 23:11
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
use WHERE clause to join the three tables
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #3 (permalink)  
Old 02-09-12, 23:17
Tharangi Tharangi is offline
Registered User
 
Join Date: Jan 2012
Posts: 10
SQL statement

I used it as follows


select flightNo,origin_airport_code,airport_name "origin" ,dest_airport_code,airport_name "dest"
from table_01 a,table_02 b
where b.airport_code=a.origin_airport_code and b.airport_code=a.dest_airport_code;


but it doesnt retrive any row.
Reply With Quote
  #4 (permalink)  
Old 02-09-12, 23:24
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
your SQL only returns rows when a.origin_airport_code=a.dest_airport_code;

select flightNo,origin_airport_code,airport_name "origin" ,dest_airport_code,airport_name "dest"
from table_01 a,table_02 b1, table_02 b2
where <you fill in missing details>
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #5 (permalink)  
Old 02-09-12, 23:25
Tharangi Tharangi is offline
Registered User
 
Join Date: Jan 2012
Posts: 10
thank you so much!!! it works !!.
Reply With Quote
  #6 (permalink)  
Old 02-09-12, 23:26
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
That is why I said THREE tables in previous response
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #7 (permalink)  
Old 02-09-12, 23:29
Tharangi Tharangi is offline
Registered User
 
Join Date: Jan 2012
Posts: 10
yes.now I can understand it.first I was confused where is the THREE tables.now it is ok Thank you again.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On