Forum Moderators: coopster

Message Too Old, No Replies

Query question

getting Unknown column error

         

mooger35

9:25 pm on Apr 18, 2007 (gmt 0)

10+ Year Member



I've been fiddling with an existing query I have for a summary of leaders on my front page... what I would like to add is a minimum number of games requirement.

This is what I have (slimmed down obviously)

$query = "SELECT stats.teamid, stats.playerid, firstname, lastname, teamname, COUNT(mins) AS gp
FROM players, stats, teams
WHERE teams.teamid = stats.teamid AND players.playerid = stats.playerid AND season = $season
GROUP BY stats.playerid
ORDER BY gaa ASC
LIMIT 0,5";

what I tried to do was add "gp > 3" to the WHERE statement. That's when I get the Unkown column error.

I could do this with an array but rather then reinventing the wheel I'd like to simply add the extra criteria into the query.

LifeinAsia

9:59 pm on Apr 18, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Try adding "HAVING COUNT(mins) > 3" after the GROUP BY line.

"gp" is an aggregate value and is not usable in WHERE conditionals.

[edited by: LifeinAsia at 10:01 pm (utc) on April 18, 2007]

mooger35

10:08 pm on Apr 18, 2007 (gmt 0)

10+ Year Member



Great!

Thanks! I just learned something new.