I could not make sense of a query, I found a workaround to get the data but I would like to know what happened.
so basically I want to obtain all ids that are not contained in another table. if I count them separately I get this:
select count(distinct product_sid)
from gaps_inp.pim_product_channel pc
where pc.channel_code = 'Amazon'
count
200658
and then count items on the other table:
select count(w.sid)
from gaps_fend.product_whitelist w
where w.channel_code = 'Amazon'
count
39697
but now if I try to count the difference:
select count(*)
from gaps_inp.pim_product_channel pc
where pc.channel_code = 'Amazon'
and pc.product_sid not in (
select w.sid
from gaps_fend.product_whitelist w
where w.channel_code = 'Amazon'
);
count
0
both fields gaps_inp.pim_product_channel.product_sid and gaps_fend.product_whitelist.sid are bigint
I was able to do it by using a left join and a where sid is null, but still I would like to know what I did wrong in the where not in query.
this is the workaround:
select count(distinct pc.product_sid)
from gaps_inp.pim_product_channel pc
left join gaps_fend.product_whitelist w on w.channel_code = 'Amazon' and pc.product_sid = w.sid
where pc.channel_code = 'Amazon'
and w.sid is null;
count
160968