I misspelled in my query and faced with MySQL\'s strange behaviour.
create table aaa (id bigint auto_increment primary key,
amount int not nul
This query:
select sum(amount)
from aaa
where id not in (select id from bbb);
Is interpreted as:
select sum(aaa.amount)
from aaa
where aaa.id not in (select aaa.id from bbb);
because bbb.id
does not exist. When writing SQL, I suggest that you always use table aliases. The query that you thought you were writing:
select sum(aaa.amount)
from aaa
where aaa.id not in (select bbb.id from bbb);
would generate the error you expect.