Solved

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

Posted on 2006-11-07
7
174 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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 …
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

825 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