简体   繁体   中英

MySQL, GROUP_CONCAT & GROUP BY

Here's my working query:

SELECT 
d.*, g.name game, 
 (SELECT GROUP_CONCAT(p.name) FROM shows_players p 
  LEFT JOIN (SELECT * FROM shows_map) sm ON sm.player_id = p.id 
  WHERE sm.show_id = d.id AND sm.game_id = g.id) players 
FROM shows_dates d 
LEFT JOIN (SELECT * FROM shows_map 
           WHERE player_id = 5 GROUP BY show_id, game_id) m ON d.id = m.show_id 
LEFT JOIN shows_games g ON g.id = m.game_id

It's a fine query until adding the "WHERE player_id =" line. Then it returns some rows with no data. How do I clean this up and get rid of these?

Thank you

A simple solution is probably to change LEFT JOIN (SELECT * FROM shows_map to INNER JOIN (SELECT * FROM shows_map .

I imagine that you get some empty NULL data since you're using LEFT JOIN.

And your query is quite the mess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM