Solved

selecting from three or more relational tables

Posted on 2013-12-27
1
184 Views
Last Modified: 2013-12-28
I have Three tables in SQL 2012.  They are related in the following scheme below.

tblGoals
GoalID - Primary Key

tblObjectives
GoalID- Foreign Key
ObjectiveID- Primary Key

tblPI
ObjectiveID- Foreign Key
PIID-Primary Key

 If I would like to call all the records between all the tables (ie, Goals, related Objectives, related PI, how would I select them all?

Would it look like this?


Select *
From tblGoals G
Inner Join tblObjective O on G.GoalID = O.GoalID Inner Join ????

You see where I am struggling....
0
Comment
Question by:al4629740
1 Comment
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 total points
ID: 39743100
You just about had it.

Select *
From tblGoals G
Inner Join tblObjective O on G.GoalID = O.GoalID
Inner Join tblPI P on O.ObjectiveID = P.ObjectiveID

That should cover it, I believe.

If you want to get more selective you can list the various columns:

select g.GoalID, O.ObjectiveID, P.PIID, etc etc etc
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

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