mysql - retrieve unique ID from aggregate function MAX/GROUP BY -
i'm getting error when using aggregate function. guys can me, explained situation below. in football/soccer game player gets red card after second yellow card. query qry1twiceyellow gives unique id of players have 2 yellow cards. query written down below , works fine. select player_id (select player_id, count(id) total yellowcards game_id=29 , homeoraway=1 group player_id) total=2; now want retrieve information last card: the unique id of last yellow card. minute offence happened. the player id . i wrote following query causes error (below query). select y.id, y.player_id, max(y.minute) lastyellow qry1twiceyellow q inner join yellowcards y on q.player_id = y.player_id y.game_id=29 , y.homeoraway=1 group y.player_id; your query not include specified expression 'id' part of aggregate function. i tried following solutions: by adding id group error disappears max(minute) aggregate function useless since id unique. leaving out unique id. inner joi...