title: GROUP BY behavior when no aggregate functions are present in the SELECT clause
body: <p>I have a table <code>emp</code> with following structure and data:</p>
  
  <pre><code>name   dept    salary
  -----  -----   -----
  Jack   a       2
  Jill   a       1
  Tom    b       2
  Fred   b       1
  </code></pre>
  
  <p>When I execute the following SQL:</p>
  
  <pre><code>SELECT * FROM emp GROUP BY dept
  </code></pre>
  
  <p>I get the following result:</p>
  
  <pre><code>name   dept    salary
  -----  -----   -----
  Jill   a       1
  Fred   b       1
  </code></pre>
  
  <p>On what basis did the server decide return Jill and Fred and exclude Jack and Tom?</p>
  
  <p>I am running this query in MySQL.</p>
  
  <p>Note 1: I know the query doesn't make sense on its own. I am trying to debug a problem with a 'GROUP BY' scenario. I am trying to understand the default behavior for this purpose.</p>
  
  <p>Note 2: I am used to writing the SELECT clause same as the GROUP BY clause (minus the aggregate fields). When I came across the behavior described above, I started wondering if I can rely on this for scenarios such as:
     select the rows from emp table where the salary is the lowest/highest in the dept. 
  E.g.: The SQL statements like this works on MySQL:</p>
  
  <pre><code>SELECT A.*, MIN(A.salary) AS min_salary FROM emp AS A GROUP BY A.dept
  </code></pre>
  
  <p>I didn't find any material describing why such SQL works, more importantly if I can rely on such behavior consistently. If this is a reliable behavior then I can avoid queries like:</p>
  
  <pre><code>SELECT A.* FROM emp AS A WHERE A.salary = ( 
              SELECT MAX(B.salary) FROM emp B WHERE B.dept = A.dept)
  </code></pre>