Description:
The expression "HAVING column_name = value" returns zero rows,
even though the expression is true.
Or it returns the wrong row (perhaps always the first row in the table?).
This happens only if I create the table with "UNIQUE (column_name)" --
if I don't, the HAVING succeeds.
How to repeat:
mysql> create table td (s1 decimal(1), unique (s1));
Query OK, 0 rows affected (0.00 sec)
mysql> insert into td values (null),(1),(2);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select s1, avg(s1) from td group by s1 having s1 = 1;
+------+---------+
| s1 | avg(s1) |
+------+---------+
| NULL | NULL |
+------+---------+
1 row in set (0.08 sec)
mysql> delete from td where s1 is null;
Query OK, 1 row affected (0.02 sec)
mysql> select s1, avg(s1) from td group by s1 having s1 = 1;
Empty set (0.00 sec)
mysql> drop table td;
Query OK, 0 rows affected (0.00 sec)
mysql> create table td (s1 decimal(1));
Query OK, 0 rows affected (0.01 sec)
mysql> insert into td values (null),(1),(2);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select s1, avg(s1) from td group by s1 having s1 = 1;
+------+---------+
| s1 | avg(s1) |
+------+---------+
| 1 | 1.0000 |
+------+---------+
1 row in set (0.01 sec)