title: Aggregated query returning 1s where 0's are expected
body: <p>In my devices table, <code>is_muted</code> is 0 for all 4 rows:</p>
  <p><a href="https://i.stack.imgur.com/xn5Sd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xn5Sd.png" alt="enter image description here" /></a></p>
  <p>yet when I run the following query:</p>
  <pre><code>SELECT
      devices.id,
      devices.hostname,
      devices.last_seen_at,
      devices.is_muted,
      SUM(CASE WHEN events.is_healthy = 0 THEN 1 ELSE 0 END) AS num_checks_unhealthy
  FROM devices
  LEFT JOIN events ON events.devices_id = devices.id
  GROUP BY devices.id
  </code></pre>
  <p>it returns <code>is_muted</code> as 1 for all devices.</p>
  <p><a href="https://i.stack.imgur.com/6xqO7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6xqO7.png" alt="enter image description here" /></a></p>
  <p>Yet if I remove <code>devices.hostname</code> from the query, is_muted returns correctly:</p>
  <pre><code>SELECT
      devices.id,
      devices.is_muted,
      SUM(CASE WHEN events.is_healthy = 0 THEN 1 ELSE 0 END) AS num_checks_unhealthy
  FROM devices
  LEFT JOIN events ON events.devices_id = devices.id
  GROUP BY devices.id
  </code></pre>
  <p><a href="https://i.stack.imgur.com/E6CA3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E6CA3.png" alt="enter image description here" /></a></p>
  <p>or if I leave devices.hostname in the SELECT but remove the JOIN, it also returns correctly:</p>
  <pre><code>SELECT
      devices.id,
      devices.hostname,
      devices.is_muted
  FROM devices
  GROUP BY devices.id
  </code></pre>
  <p><a href="https://i.stack.imgur.com/hhJ1B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hhJ1B.png" alt="enter image description here" /></a></p>
  <p>Can someone please help me figure out what am I misunderstanding? Why does <code>is_muted</code> return 1 rather than 0 when I select another random TEXT column from the same table, or use a JOIN? Where is the 1 coming if all values in the <code>is_muted</code> column are 0?</p>
  <h2>Update</h2>
  <p>Selecting is_muted in an IF statement is returning the expected data:</p>
  <pre><code>SELECT 
    devices.id,
    devices.hostname,
    devices.last_seen_at,
    IF(devices.is_muted = 1, TRUE, FALSE) AS muted,
  sum(case when events.is_healthy = 0 then 1 else 0 end) AS num_checks_unhealthy,
  sum(case when events.is_healthy = 1 then 1 else 0 end) AS num_checks_healthy
  FROM devices
  LEFT JOIN events ON events.devices_id = devices.id
  GROUP BY devices.id
  </code></pre>
  <p><a href="https://i.stack.imgur.com/r8KPw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r8KPw.png" alt="enter image description here" /></a></p>
  <p>I tested this by muting one device and verified the response:</p>
  <p><a href="https://i.stack.imgur.com/RMlip.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RMlip.png" alt="enter image description here" /></a></p>