SQL Query

Hopefully a simple one, thouhg I am too knackered to work it out (lazy oik)

I have a MATCH table which has a home team and an away team

MatchID (PK)
HomeTeam
AwayTeam

Both the Home and Away team pull off the team from the same table of teams

TEAMS
TeamID (PK)
TeamName

There is more information but it is not important.

I know how to code a simple SELECT staement using a JOIN to pull of the name of ONE of the teams, but have never done it for TWO.. any help appreicated.

Thanks
LVL 3
mvwmailAsked:
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.

smaglio81Commented:
SELECT      tone.TeamName as HomeTeam, ttwo.TeamName as AwayTeam
FROM      m INNER JOIN
            teams tone ON m.HomeTeam = tone.TeamID INNER JOIN
            teams ttwo ON m.AwayTeam = ttwo.TeamID
WHERE      m.MacthID = <cfqueryparam cfsqltype="cf_sql_integer" value="#id#" />
0
mvwmailAuthor Commented:
My app does not like that at ALL, throws a wobbler.. and I cant work throuhg it enouhg to debug. Dont know if it makes a difference but my database is Access.

Will have another go in a bit.. need coffee
0
smaglio81Commented:
I don't know then. I don't have enough experience with Access and Coldfusion.

Steven
0
INSDivision6Commented:
Try this:

SELECT c.MatchID,a.TeamName as HomeTeamName,b.TeamName as AwayTeamName
FROM TEAMS a,TEAMS b,MATCH c
WHERE c.MatchID=#MatchID# and c.HomeTeam=a.TeamID and c.AwayTeam=b.TeamID



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
mvwmailAuthor Commented:
Fantastic..
works a treat.. thanks =)
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
Web Servers

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.