Description:
When the DISTINCT syntax is added to the SQL, the result mismatches.
How to repeat:
CREATE TABLE t1 (
a INT,
b INT);
INSERT INTO t1 VALUES(1, 2), (3, 4);
root@localhost:test 8.0.16-rds-dev> SELECT if(COALESCE(aa.a, 'hope') = 'hope', 'hope', group_concat(distinct concat(aa.a, ""))) FROM t1 aa LEFT JOIN t1 bb ON aa.a = bb.a GROUP BY bb.b, aa.a;
+--------------------------------------------------------------------------------------+
| if(COALESCE(aa.a, 'hope') = 'hope', 'hope', group_concat(distinct concat(aa.a, ""))) |
+--------------------------------------------------------------------------------------+
| 1 |
| 3 |
+--------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
root@localhost:test 8.0.16-rds-dev> SELECT DISTINCT if(COALESCE(aa.a, 'hope') = 'hope', 'hope', group_concat(distinct concat(aa.a, ""))) FROM t1 aa LEFT JOIN t1 bb ON aa.a = bb.a GROUP BY bb.b, aa.a;
+--------------------------------------------------------------------------------------+
| if(COALESCE(aa.a, 'hope') = 'hope', 'hope', group_concat(distinct concat(aa.a, ""))) |
+--------------------------------------------------------------------------------------+
| 1 |
+--------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
The above results of the two queries are obviously inconsistent.