title: SQL aggregation with where
body: <p>We have the following table:
  | name | legs | weight|
  |------|------|-------|
  |bird  |2     |6      |
  |cat   |4     |10     |
  |dog   |4     |20     |
  |ferret|4     |10     |
  |penguin|2    |10      |
  |t-rex  |2     |12000      |
  and if I run the first query:</p>
  <pre><code>select min(legs), max(weight), name from animals;
  </code></pre>
  <p>the result is:
  | min(legs) | max(weight) | name|
  |------|------|-------|
  |2  |12000     |t-rex      |
  and if I run the second query in which I add a where condition:</p>
  <pre><code>select min(legs), max(weight), name from animals where name &lt;&gt; &quot;t-rex&quot;;
  </code></pre>
  <p>the result is:
  | min(legs) | max(weight) | name|
  |------|------|-------|
  |2  |20    |dog      |</p>
  <p>I don't understand why in second case name is dog. My understanding is that we exclude t-rex row, and do query from the rest of rows. Then we select min of legs, which is 2, max of weight, which is 20. And apparently min of legs 2 and max of weight 20 are not in the same row.</p>