Solved

selecting from three or more relational tables

Posted on 2013-12-27
1
177 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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

744 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

20 Experts available now in Live!

Get 1:1 Help Now