Solved

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

Posted on 2006-11-07
7
150 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
7 Comments
 
LVL 7

Accepted Solution

by:
bwasyliuk earned 84 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 83 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 83 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now