At a guess, because you use @team in an if statement before you actually define it.
On Sun, Sep 26, 2010 at 12:35 AM, Tompkins Neil < neil.tompk...@googlemail.com> wrote: > Hi, > > I've the following query > > SELECT teams_id AS teams_id ,SUM(rating) AS total_team_rating FROM (SELECT > teams_id ,players_id ,rating ,IF(@team <> teams_id, @row := 1, @row := @row > + 1) AS rank ,@team := teams_id FROM ( SELECT players.teams_id > ,players.players_id ,players_master.rating FROM players JOIN players_master > ON players.players_id = players_master.players_id WHERE players.worlds_id = > 1 AND players.red_cards = 0 AND players.injury_duration_remaining = 0 AND > players.teams_id > 0 ORDER BY players.teams_id, players_master.rating DESC) > s1) s2 WHERE rank <= 11 GROUP BY teams_id ORDER BY total_team_rating DESC > > I'm running MySQL 5.0.77. However, if I run this query nothing is > returned, > but if I run the query again I get the desired results. Why is this ? > > Cheers > Neil > -- Bier met grenadyn Is als mosterd by den wyn Sy die't drinkt, is eene kwezel Hy die't drinkt, is ras een ezel