×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Writing a SQL statement to link fields from 3 tables.

Writing a SQL statement to link fields from 3 tables.

Writing a SQL statement to link fields from 3 tables.

(OP)
Hi, I'm a beginner to databases and querying so hope you can help me out!

I have 4 tables involved: FLIGHT_LEG, FLIGHT_DATE_GEN, ACTIVE_SCENARIO, SCENARIO

The problem is that the FLIGHT_DATE_GEN table doesn't have a scenario field (which I want). Each record should have a corresponding scenario. The table however has a field called FLIGHT_DATE which is unique and also present in the FLIGHT_LEG table.

The FLIGHT_LEG table in turn has a field called MULTI_USER_SESSION_ID, which is not unique but is also present in the ACTIVE_SCENARIO table. This table has a SCENARIO_ID field which is also present in the SCENARIO table.

And finally in the SCENARIO table there is a field called SCENARIO_NAME, which corresponds to each SCENARIO_ID.

I need to extact all the data in the FLIGHT_DATE_GEN table and also have a column that contains the data from the SCENARIO_NAME field.

Hope that wasn't too confusing, how can I write a SQL statement to get this data?

Thanks for reading, and I appreciate any help.

Colin

RE: Writing a SQL statement to link fields from 3 tables.

SELECT FLIGHT_DATE_GEN.*,SCENARIO_NAME FROM FLIGHT_DATE_GEN
LEFT JOIN FLIGHT_LEG ON FLIGHT_LEG.FLIGHT.DATE=FLIGHT_DATE_GEN.FLIGHT_DATE
LEFT JOIN ACTIVE_SCENARIO ON ACTIVE_SCENARIO.MULTI_USER_SESSION_ID=FLIGHT_LEG.MULTI_USER_SESSION_ID
LEFT JOIN SCENARIO ON SCENARIO.SCENARIO_ID=ACTIVE_SCENARIO.SCENARIO_ID

RE: Writing a SQL statement to link fields from 3 tables.

(OP)
Thank you very much.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources