diff --git a/mysql-test/suite/innodb/r/partition-blob.result b/mysql-test/suite/innodb/r/partition-blob.result index b6cea1174ca..4bacd32748f 100644 --- a/mysql-test/suite/innodb/r/partition-blob.result +++ b/mysql-test/suite/innodb/r/partition-blob.result @@ -23,7 +23,7 @@ INSERT INTO t1 VALUES(1,'1', 3); INSERT INTO t1 VALUES(2,'2', 2); INSERT INTO t1 VALUES(3,'3', 2); SELECT DISTINCT f3 FROM t1 -HAVING (SELECT 1 FROM t1 HAVING f2 LIMIT 1) +HAVING (SELECT 1 FROM t1 HAVING f3 LIMIT 1) ORDER BY f3; f3 2 diff --git a/mysql-test/suite/innodb/t/partition-blob.test b/mysql-test/suite/innodb/t/partition-blob.test index 5ea8911d18a..6f47e00fb9a 100644 --- a/mysql-test/suite/innodb/t/partition-blob.test +++ b/mysql-test/suite/innodb/t/partition-blob.test @@ -28,7 +28,7 @@ INSERT INTO t1 VALUES(2,'2', 2); INSERT INTO t1 VALUES(3,'3', 2); SELECT DISTINCT f3 FROM t1 -HAVING (SELECT 1 FROM t1 HAVING f2 LIMIT 1) +HAVING (SELECT 1 FROM t1 HAVING f3 LIMIT 1) ORDER BY f3; DROP TABLE t1; diff --git a/sql/item.cc b/sql/item.cc index de0da1ba57f..e79edab5777 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -7303,7 +7303,8 @@ bool Item_ref::fix_fields(THD *thd, Item **reference) { ER_BAD_FIELD_ERROR which we produce now. */ if ((place != CTX_HAVING || - (!select->with_sum_func && select->group_list.elements == 0))) { + (!select->with_sum_func && select->group_list.elements == 0)) + && !(outer_context->select_lex && outer_context->select_lex->is_distinct() && place == CTX_HAVING)) { /* In case of view, find_field_in_tables() write pointer to view field expression to 'reference', i.e. it substitute that