 <p>MySQL is awfully lax when it comes to the <code>GROUP BY</code>-clause. In MySQL, you can add columns to your select clause that are not in the <code>GROUP BY</code> or an aggregate functions. Other RDBMS do not allow this, as it makes no sense semantically. MySQL just returns more or less random row values that fit the given query. </p> <p>From the <a href="http://dev.mysql.com/doc/refman/5.6/en/group-by-hidden-columns.html">MySQL Doc</a></p> <blockquote> <p>In standard SQL, a query that includes a GROUP BY clause cannot refer to nonaggregated columns in the select list that are not named in the GROUP BY clause. [...] MySQL extends the use of GROUP BY so that the select list can refer to nonaggregated columns not named in the GROUP BY clause. </p> </blockquote> <p>What you have to do is, find out what the query is supposed to do and rewrite it.</p>