SELECT g.id AS game_id, g.results_order, g.comp_id, if(g.play='TEAM',gp.team_id, gp2.person_id) as team_id, g.phaze_id, if(g.play='TEAM',if(t.short!='',t.short, t.name), CONCAT(gp2.fname,' ',gp2.lname)) as name,
if(g.play='TEAM',t.is_guest, gp2.type='GHOST') as is_guest, c.image, g.name AS gname, g.group,
if(g.play='TEAM',gp.score,gp2.score) as score, loc.name AS location, g.time, g.status, g.period_id, ph.type AS phase_type, g.bracket, if(g.play='TEAM',if(t.short!='', t.short, if(c.short!='',c.short,t.name)),
CONCAT(gp2.fname,' ',gp2.lname)) as short, if(g.play='TEAM',gp.irm, gp2.irm) as irm, g.bracket_size, g.bracket_pos
FROM games AS g
Left JOIN game_participants AS gp ON gp.game_id = g.id and g.play='TEAM'
Left JOIN (select gs.*, sr.club_id as team_id, p.fname, p.lname, p.type from game_singles as gs
inner join games as g on g.id=gs.game_id
left JOIN single_rankings AS sr ON sr.player_id = gs.person_id and sr.comp_id=g.comp_id
inner join people as p on p.id=gs.person_id) AS gp2 ON gp2.game_id = g.id and g.play='SINGLE'
left JOIN teams AS t ON (gp.team_id = t.id) OR (gp2.team_id = t.id)
left JOIN clubs AS c ON t.club_id = c.id
LEFT JOIN phazes AS ph ON ph.id = g.phaze_id
LEFT JOIN location AS loc ON loc.id = g.location
WHERE g.comp_id = 2439 AND ph.level = 2 AND g.type!='SUBMATCH'
ORDER BY bracket, g.time, g.id, if(g.play='TEAM',gp.id, gp2.id), t.name ASC
SELECT g.id AS game_id, g.results_order, g.comp_id, if(g.play='TEAM',gp.team_id, gp2.person_id) as team_id, g.phaze_id, if(g.play='TEAM',if(t.short!='',t.short, t.name), CONCAT(gp2.fname,' ',gp2.lname)) as name,
if(g.play='TEAM',t.is_guest, gp2.type='GHOST') as is_guest, c.image, g.name AS gname, g.group,
if(g.play='TEAM',gp.score,gp2.score) as score, loc.name AS location, g.time, g.status, g.period_id, ph.type AS phase_type, g.bracket, if(g.play='TEAM',if(t.short!='', t.short, if(c.short!='',c.short,t.name)),
CONCAT(gp2.fname,' ',gp2.lname)) as short, if(g.play='TEAM',gp.irm, gp2.irm) as irm, g.bracket_size, g.bracket_pos
FROM games AS g
Left JOIN game_participants AS gp ON gp.game_id = g.id and g.play='TEAM'
Left JOIN (select gs.*, sr.club_id as team_id, p.fname, p.lname, p.type from game_singles as gs
inner join games as g on g.id=gs.game_id
left JOIN single_rankings AS sr ON sr.player_id = gs.person_id and sr.comp_id=g.comp_id
inner join people as p on p.id=gs.person_id) AS gp2 ON gp2.game_id = g.id and g.play='SINGLE'
left JOIN teams AS t ON (gp.team_id = t.id) OR (gp2.team_id = t.id)
left JOIN clubs AS c ON t.club_id = c.id
LEFT JOIN phazes AS ph ON ph.id = g.phaze_id
LEFT JOIN location AS loc ON loc.id = g.location
WHERE g.comp_id = 2439 AND ph.level = 3 AND g.type!='SUBMATCH'
ORDER BY bracket, g.time, g.id, if(g.play='TEAM',gp.id, gp2.id), t.name ASC
SELECT g.id AS game_id, g.results_order, g.comp_id, if(g.play='TEAM',gp.team_id, gp2.person_id) as team_id, g.phaze_id, if(g.play='TEAM',if(t.short!='',t.short, t.name), CONCAT(gp2.fname,' ',gp2.lname)) as name,
if(g.play='TEAM',t.is_guest, gp2.type='GHOST') as is_guest, c.image, g.name AS gname, g.group,
if(g.play='TEAM',gp.score,gp2.score) as score, loc.name AS location, g.time, g.status, g.period_id, ph.type AS phase_type, g.bracket, if(g.play='TEAM',if(t.short!='', t.short, if(c.short!='',c.short,t.name)),
CONCAT(gp2.fname,' ',gp2.lname)) as short, if(g.play='TEAM',gp.irm, gp2.irm) as irm, g.bracket_size, g.bracket_pos
FROM games AS g
Left JOIN game_participants AS gp ON gp.game_id = g.id and g.play='TEAM'
Left JOIN (select gs.*, sr.club_id as team_id, p.fname, p.lname, p.type from game_singles as gs
inner join games as g on g.id=gs.game_id
left JOIN single_rankings AS sr ON sr.player_id = gs.person_id and sr.comp_id=g.comp_id
inner join people as p on p.id=gs.person_id) AS gp2 ON gp2.game_id = g.id and g.play='SINGLE'
left JOIN teams AS t ON (gp.team_id = t.id) OR (gp2.team_id = t.id)
left JOIN clubs AS c ON t.club_id = c.id
LEFT JOIN phazes AS ph ON ph.id = g.phaze_id
LEFT JOIN location AS loc ON loc.id = g.location
WHERE g.comp_id = 2439 AND ph.level = 4 AND g.type!='SUBMATCH'
ORDER BY bracket, g.time, g.id, if(g.play='TEAM',gp.id, gp2.id), t.name ASC