A: 

Why does the second query reference "player"? I don't see you mention such a table anywhere else... ("FROM players, player") Just making sure that's deliberate.

It might be helpful to avoid mixing explicit joins (eg "LEFT JOIN") with implicit joins (eg "FROM players, player"), in order to keep your structure consistent.

DreadPirateShawn
I need the player name from the `player` table, I reference it before the `CASE` statement
Anriëtte Combrink
+3  A: 

You haven't been specific enough about the data but, assuming there is one record in each associated table per player and you're happy to show NULL if it's not there then:

SELECT player_id, tries, conversions, penalties, dropgoals
FROM players p
LEFT JOIN tries t ON t.player_id = p.player_id
LEFT JOIN conversions c ON c.player_id = p.player_id
LEFT JOIN penalties e ON e.player_id = p.player_id
LEFT JOIN dropgoals d ON d.player_id = p.player_id

This can be restated as:

SELECT player_id
(SELECT tries FROM tries WHERE player_id = p.player_id) tries,
(SELECT conversions FROM conversions WHERE player_id = p.player_id) conversions,
(SELECT penalties FROM penalties WHERE player_id = p.player_id) penalties,
(SELECT dropgoals FROM dropgoals WHERE player_id = p.player_id) dropgoals
FROM players p

Performance may or may not vary depending on your database engine. If you need to sum this then change it to:

SELECT player_id
(SELECT SUM(tries) FROM tries WHERE player_id = p.player_id) tries,
(SELECT SUM(conversions) FROM conversions WHERE player_id = p.player_id) conversions,
(SELECT SUM(penalties) FROM penalties WHERE player_id = p.player_id) penalties,
(SELECT SUM(dropgoals) FROM dropgoals WHERE player_id = p.player_id) dropgoals
FROM players p

Any of the above can use IFNULL() or similar functions to return 0 instead of NULL, if desired.

cletus
Thanks Cletus, I just tried that multiple left joins, and it worked! Just checked for any new answers, and saw you had the solution as well, thanks for your trouble, you really are on of the best.
Anriëtte Combrink
Hi, Cletus, sorry for removing the solution to your answer, because, well, it did count the types of scoring, but ultimately did not solve my question.
Anriëtte Combrink
+1  A: 

I'm a little confused why you stated Cletus had the correct solution, and proceeded to not use it while updating your original question. That said, Cletus' solution is slightly off, you need COUNT() not SUM(). Try the following:

SELECT players.player_id,
(SELECT COUNT(*) FROM tries WHERE player_id = players.player_id) tries,
(SELECT COUNT(*) FROM penalties WHERE player_id = players.player_id) penalties
FROM players;

This will return 0's instead of &nbsp I'd recommend handling that in your application code though. You can add in the CASE mess if you really want to get the &nbsp from mysql.

hobodave
This is obviously pared down, but will work once you add the additional joins, wheres, and group by.
hobodave
So, correct me if I'm wrong, I should replace my `LEFT JOIN`'s with nested `SELECT` statements only where I need to `COUNT` anything. I used `CASE` because I assumed it may be faster doing the validating in MySQL and there was no additional PHP validation necessary. What do you suggest?
Anriëtte Combrink