?
Solved

Need an example of a query of how to pull record data from three tables?

Posted on 2006-11-07
7
Medium Priority
?
208 Views
Last Modified: 2013-12-24
Hi,

I need to write a query that pulls information from three different tables, and joins the information from the three tables into one record.

Each table has one field in common with the others.  
That field is RequestID.
From table A I need to pull RequestID, LoadedLOE.
From table B I need to pull RequestID, ReleaseMonth, ReleaseYear.
From table C I need to pull RequestID, Subline.

The query needs to combine these records into my table D.

Thanks in advance for your time.
0
Comment
Question by:g118481
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 7

Accepted Solution

by:
bwasyliuk earned 336 total points
ID: 17891876
Are you inserting this into table D - or do you just need this data as a query record set?

here is the query:

Select
 A.RequestID,
 A.LoadedLOE,
 B.ReleaseMonth,
 B.ReleaseYear,
 C.SubLine
FROM Table1 A
  JOIN Table2 B ON A.RequestID = B.RequestID
  JOIN Table3 C ON A.RequestID = C.RequestID

Does this give you the result set you are looking for?

Ben
www.scheduleforce.net
0
 
LVL 15

Assisted Solution

by:danrosenthal
danrosenthal earned 332 total points
ID: 17891879
Here is the SELECT:

SELECT
      a.RequestID, a.LoadedLOE
      ,b.ReleaseMonth, b.ReleaseYear
      c.Subline
FROM
      tableA a, tableB b, tableC c
WHERE a.RequestID = b.RequestID
AND a.RequestID = c.RequestID


If you want to insert the results into Table D you would do this:

INSERT INTO tableD (requestID, LoadedLOE, ReleaseMonth, etc...)
SELECT a.RequestID
      , a.LoadedLOE
      , b.ReleaseMonth
      , etc....
0
 
LVL 20

Assisted Solution

by:trailblazzyr55
trailblazzyr55 earned 332 total points
ID: 17898489
here's an easy method to select everything you need into a new table in a single query...

SELECT A.RequestID, B.ReleaseMonth, B.ReleaseYear, C.Subline
INTO Tabel4
FROM Table1 A INNER JOIN Table2 B ON A.RequestID = B.RequestID
              INNER JOIN Table3 C ON A.RequestID = C.RequestID
0
 
LVL 2

Expert Comment

by:theamzngq
ID: 17908576
and yet another variation (just for fun):

select requestid,releasemonth,releaseyear,subline
into table4
from
  table1 inner join table2 using(requestid)
  inner join table3 using(requestid)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question