I have 4 tables, named:

players - stores player id, name, team id
teams - teamid, teamname
goals - goals scored, player id, team id
penalty - penaltys accumulated, player id

What I'm trying to do is write a query to get the top 10 from any category
and display them.  I can do them individually fine, like so:

SELECT players.PLAYERID, players.FIRSTNAME, players.LASTNAME,
SUM(penalty.PENALTYMINUTES) as TTPM FROM players, penalty where
(penalty.PLAYERID = players.PLAYERID) GROUP BY PLAYERID ORDER BY TTPM DESC
LIMIT 10


but when I try to get the goal total as well or something and add another
table to the from statement, I appear to be getting too many rows back as
the numbers are inflated about 10 times what they should be .. the query I'm
working with is:

SELECT teams.TEAMNAME, players.PLAYERID, players.FIRSTNAME,
players.LASTNAME, SUM(penalty.PENALTYMINUTES) as TPM, COUNT(goals.SCORER) as
TGOALS FROM players, penalty, teams, goals where (penalty.PLAYERID =
players.PLAYERID AND players.TEAMID = teams.TEAMID AND goals.SCORER =
players.PLAYERID AND goals.TEAMID = teams.TEAMID) GROUP BY PLAYERID ORDER BY
TPM DESC LIMIT 10


I'm not sure how I would go about re-writing it to get it to work properly,
and humbly beg for assistance.

Thanks,
Chad


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to