diff --git a/sql/sql_select.cc b/sql/sql_select.cc index b87f88a3988..f7a0d5259a6 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -933,7 +933,7 @@ JOIN::optimize() If having is not handled here, it will be checked before the row is sent to the client. */ - if (having && + if (tmp_having && (sort_and_group || (exec_tmp_table1->distinct && !group_list))) having= tmp_having;