Using the following query I getting the result like how much the players in the table, but now I also want which players are in the same table, and show those players id with a
The function you are looking for is GROUP_CONCAT
. See the documentation:
http://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html#function_group-concat
In your example you can just create one more subquery (example below). Or JOIN
it in a standard way to the original query.
...
(
SELECT GROUP_CONCAT(gtp.id)
FROM game_table_players gtp
LEFT JOIN game_rounds gr ON gr.id = gtp.game_round_id
WHERE gt.id = gtp.game_table_id
AND gtp.quit<>1 AND gr.finish=0
) AS players,
...
Note the comment on NULL
handling in GROUP_CONCAT
. If you want to show zeros when there aren't any players present, you might want to use COALESCE(GROUP_CONCAT(gtp.id), 0)
instead.