How to return different result in the same query?
null
isn't a value, it's the lackthereof. null = null
returns null
, not true
, so for groups without an id, this query won't work.
You can use the <=>
instead of =
, though, to evaluate two null
s as being equal:
SELECT l.*,t.name as team_name,r.name AS rank_name,r.color AS rank_colorFROM league_ranking lLEFT JOIN team t ON l.team_id = t.idLEFT JOIN competition_ranks r ON l.rank = r.idINNER JOIN competition_groups g WHERE l.round_id = :round_idAND l.group_id <=> ( -- <=> used here instead of = SELECT MIN(l2.group_id) FROM league_ranking l2 WHERE l2.round_id = :round_id)