I'm querying on this table:
SKU
aaaa
bbbb
bbbb
NULL
Here's the query:
select *
from TEST as N
where N.SKU NOT IN (select SKU
from TEST
group by SKU
having count(*)>1);
I expect the query returns 'aaaa', however, it returns nothing.
The reason I expect that is because the subquery below only returns 'bbbb':
select SKU
from TEST
group by SKU
having count(*)>1
Therefore, 'aaaa' NOT IN the subquery result.
To show the bug please copy and paste these statements in your MySQL IDE to create schema:
drop table if exists TEST;
create table TEST(
SKU varchar(255)
);
insert into TEST values('aaaa'),('bbbb'),('bbbb'),(NULL);
Even more confusing, try this new table below, re-run the query, and check result:
drop table if exists TEST;
create table TEST(
SKU varchar(255)
);
insert into TEST values('aaaa'),('cccc'),('dddd'),('bbbb'),('bbbb'),(NULL);
Expect 'aaaa', 'cccc', 'dddd' are all returned, however 'aaaa' is missing, yet 'cccc' and 'dddd' are returned.