[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2006-11-07
7
Medium Priority
?
220 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:David Williamson
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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

656 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