Hi everyone. I'm trying get data with in the following way:
$query = "SELECT g.game_id, g.play_date, p.name, gp.gain,
(SELECT SUM(gp2.gain) FROM \Multiple\Frontend\Models\GamePlayer gp2
LEFT JOIN \Multiple\Frontend\Models\Game g2 ON (g2.game_id = gp2.game_id)
WHERE g2.play_date <= '{$date}' AND gp2.player_id = gp.player_id) as total
FROM \Multiple\Frontend\Models\GamePlayer gp
INNER JOIN \Multiple\Frontend\Models\Game g ON g.game_id = gp.game_id
INNER JOIN \Multiple\Frontend\Models\Player p ON p.player_id = gp.player_id
WHERE g.play_date = '{$date}'
GROUP BY gp.player_id
ORDER BY total DESC"
;
$query = new Query($query, \Phalcon\DI\FactoryDefault::getDefault());
return $query->execute();
After add the part "(...)LEFT JOIN \Multiple\Frontend\Models\Game g2(...)" on query, i started to receive the follow error message:
SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'g2'
I tried add "as" before alias, rename alias, and nothing's ok. Someone can help-me? Thanks very much!