Solved

selecting from three or more relational tables

Posted on 2013-12-27
1
186 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
[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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.

730 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