MySQL get name of last added value on group by query -
I want to show in the videogame cheats and tips page in an index where all the available cheats are listed, the results are grouped by videogame Doing and counting how many cheats in the video game is counting, I can fulfill it, but I am trying to show the last deceit in the game.
My query is:
Select a_games.game_id, cheat_count as COUNT (*), a_games.game_fname, a_games.game_logo, a_cheats a_cheats.cheat_title On the left a_games a_games.game_id = a_cheats.game_id group include a_cheats.game_id This only shows the first added fraud.
I tried to use the maximum on cheat_id but the value added cheat_title shows the previously added fraud.
table a_cheats
cheat_id type_id member_ id game_id cheat_title cheat_body cheat_date 1 | 1 | 1 | 22 | Troaks Wei ... | Introduz ... | 2014-10- | 2 | 1 | 1 | 25 | Invulnera ... | Durante ... | 2014-10- | 3 | 1 | 1 | 25 | Modo Debu ... | Durante ... | 2014-10- | 4 | 1 | 1 | 25 | Charm in ... | Durante ... | 2014-10- | 5 | 1 | 1 | 36 | Cabeças e ... | Kuka o ... | 2014-10- |
table a_games
game_id genre_id member_id game_fname game_sname game_logo 22 | 15 | 1 | 4x4 Whirl ... | | 525 90 0 ... 25 | 3 | 1 | Ajeeji th ... | | 5287ae0 ... 36 | 25 | 1 | All Star ... | | 5287daa ...
Therefore the consequence of Ajji should be shown to the deceitful "Charm Infinito" which is the last deceit for that game
query results
game_id game_count game_fname game_logo cheat_title 22 | 1 | 4x4 World Trophy | 525 9D0527128_ ava_4x4worldtrophy.jpg | Trucs (Varius) 25 | 3 | Ajeeji heartless 5287ae093e115_ava_akujiheartless.jpg | Constitutional 36 | 1 | All Star Tennis '99 | 5287daa2695ef_ava_allstartennis99.jpg | Once you call count ()
code>, You can not control the title
to take it later (it gets the title of the initial entry directly). . Thus, we can count what you want by calling later
Note: You can set the order by a_cheats.cheat_date DESC by a_cheats.cheat_id DESC
order Can change if you want it to be more reliable
select GameID, gameName, cheatTitle, select as cheat_count the COUNT (GameID) (a_games. GameID, gameName a_games form. game_fname, a_cheats.cheat_title cheatTitle the a_cheats a_cheats.cheat_id DESC by a_games.game_id = a_cheats.game_id order a_games Join) GameID
as by ungroup Group game_id
SQLFiddle:
or
SQLFiddle:
Comments
Post a Comment