We help IT Professionals succeed at work.
Get Started

query / sproc, SELECTING FROM a SELECT statement with JOINs

79 Views
Last Modified: 2015-03-08
SIMPLIFIED!

7Teams TABLE col ParentTeamID has multiple entries of same ParentTeamID
Contacts TABLE col ParentTeamID, FirstName, etc...

Current Solution below gives the correct result:

*a VIEW named vDistinctTeams
-SELECT DISTINCT ParentTeamID
-FROM         dbo.[7Teams]

*then
SELECT     dbo.vDistinctTeams.ParentTeamID, dbo.Contacts.FirstName
FROM         dbo.vDistinctTeams LEFT OUTER JOIN
                      dbo.Contacts ON dbo.vDistinctTeams.ParentTeamID = dbo.Contacts.ContactID

*the above yields 1 row for each unique ParentTeamID in  the 7Teams Table  and its Name (and any other fields I need) from the Contacts Table

PROBLEM:  I need to do this in 1 Query (Sproc)  (I am new to db) like below...

SELECT ParentID, FirstName, etc
FROM   SELECT DISTINCT ParentTeamID
              FROM 7Teams   ??JOIN??   Contacts


Thanks in advance!
Sam
Comment
Watch Question
Senior Software Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE