query / sproc, SELECTING FROM a SELECT statement with JOINs

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
SamCashAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Walter RitzelSenior Software EngineerCommented:
In theory, that should do:
SELECT     distinct dbo.7Teams.ParentTeamID, dbo.Contacts.FirstName
FROM         dbo.7Teams LEFT OUTER JOIN
                      dbo.Contacts ON dbo.7Teams.ParentTeamID = dbo.Contacts.ContactID

Open in new window


or this:
SELECT     a.ParentTeamID, dbo.Contacts.FirstName
FROM         (SELECT DISTINCT ParentTeamID FROM dbo.[7Teams])  a LEFT OUTER JOIN
                      dbo.Contacts ON a.ParentTeamID = dbo.Contacts.ContactID

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
Why do you even need to join with 7Teams table?
You have all information in the Contacts table.
SELECT ContactID, FirstName
FROM dbo.Contacts

Open in new window

Or do you need any particular field from 7Teams table?
0
SamCashAuthor Commented:
Great, the second was used effectively, thanks for the simplified answer!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.