MySQL Forums
Forum List  »  Newbie

Re: EXPLAIN shows optimized query
Posted by: Peter Brawley
Date: November 18, 2017 11:18AM

You need to re-read the manual section on aggregation.

select a, b, c, d, group_concat(e), ...
from ...
group by a;

will return indeterminate, arbitrary results for `b`, `c` and `d` unless values of `a` perfectly determine values of `b`, `c` and `d`.

If you don't know whether this is so, then (i) the table is inadequately normalised and (ii) you can find out if it's so by adding b, c, d to the group by clause and comparing the query result: only if they're identical is it valid to leave `b`, `c` and `d` out of the group by clause.

To protect against a tendency to write such mistakes, include only_full_group_by in the sql_mode setting.

Options: ReplyQuote


Subject
Written By
Posted
October 31, 2017 03:11AM
Re: EXPLAIN shows optimized query
November 18, 2017 11:18AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.