Bug #5400 GROUP_CONCAT returns everything twice
Submitted: 3 Sep 2004 21:15 Modified: 8 Sep 2004 18:42
Reporter: Ronald Weiss Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.4 OS:Windows (win2003)
Assigned to: Sergey Petrunya CPU Architecture:Any

[3 Sep 2004 21:15] Ronald Weiss
Description:
GROUP_CONCAT returns everything twice, when used with DISTINCT or ORDER BY, and is at the same time referenced in HAVING clause

example:
SELECT GROUP_CONCAT( DISTINCT x ) AS col1 GROUP BY y HAVING col1 LIKE '%'

without DISTINCT & ORDER BY, everything is ok
without beeing referenced in HAVING, everything is also ok
it works bad only with these two together

How to repeat:
CREATE TABLE table1 ( col1 INT, col2 INT );
  > Query OK, 0 rows affected (0.00 sec)

INSERT INTO table1 VALUES (1,1),(1,2),(1,3),(2,1),(2,2);
  > Query OK, 5 rows affected (0.00 sec)
  > Records: 5  Duplicates: 0  Warnings: 0

SELECT GROUP_CONCAT( DISTINCT col1 ) AS alias FROM table1
GROUP BY col2 HAVING alias LIKE '%';
  > +---------+
  > | alias   |
  > +---------+
  > | 1,2,1,2 |
  > | 1,2,1,2 |
  > | 1,1     |
  > +---------+
  > 3 rows in set (0.00 sec)
[8 Sep 2004 2:19] Sergey Petrunya
ChangeSet@1.2008, 2004-09-08 06:26:18+04:00, sergefp@mysql.com
[8 Sep 2004 18:42] Sergey Petrunya
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

ChangeSet@1.2007.1.1, 2004-09-08 22:43:37+04:00, sergefp@mysql.com