3 table mysql join showing all rows

I have 3 tables:

--team
teamId | teamName

--round
roundId | roundName

--score - linking table
teamId | roundId | score

I want to create a table showing rounds along the top and teams down the left with scores at the appropriate place (if they have them).

Ideally I would like 1 query to show all the data and I can then use PHP to sort through the data into the table.

Question:
How do I create a query that outputs all teams, all rounds, and scores if they have them... otherwise null

Query output example that might work:
teamId | teamName | roundId | roundName | score
1        namea      1         TV          7
2        nameb      1         TV          null
3        namec      1         TV          2
4        named      1         TV          9
1        namea      2         radio       4
2        nameb      2         radio       3
3        namec      2         radio       7
4        named      2         radio       1
1        namea      3         sport       null
2        nameb      3         sport       null
3        namec      3         sport       null
4        named      3         sport       null

Open in new window

In the above example
- team 2 round 1 didn't play
- round 3 hasn't been played yet


This query doesnt show all the rounds:
SELECT * FROM team
LEFT JOIN score ON team.teamId = score.teamId
LEFT JOIN round ON score.roundId = round.roundId

Open in new window

I can then use while loops to go through the data and built the table.......
Unless anyone else has a better idea?
Steve TinsleyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Steve TinsleyAuthor Commented:
See another question I created:
http://www.experts-exchange.com/questions/28832240/MySQL-Scoreboard-with-Ranking.html

But I think the mysql method of building a piviot table is too complex and goes over my head!
ste5anSenior DeveloperCommented:
You need a Cartesian JOIN for team X round and LEFT JOIN your scores:

SELECT  *
FROM    rounds R
        CROSS JOIN teams T
        LEFT JOIN scores S ON S.teamId = T.teamId
                               AND S.roundId = R.roundId;

Open in new window

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
Steve TinsleyAuthor Commented:
That is prefect!
Many Thanks!
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
MySQL Server

From novice to tech pro — start learning today.