我有以下MySQL查询:
select c.company_id,c.company_name, pe.pe_relationship, opt.oo_type
from pub_entity pe
inner join company c
on c.company_id = pe.pe_company_id
inner join opt_out opt
on opt.oo_company_id=c.company_id
where pe.pe_pn_id in
(SELECT pn_id
FROM pub_notice
WHERE pn_company_id=2523);
and opt.oo_type not in
('image','iframe')
但是,当我运行查询时,在opt.oo_type
列中,我仍然会收到image
和iframe
个结果。
opt.oo_type
的类型为enum('image','iframe','other')
任何人都可以告诉我为什么我仍然会得到这些结果?
答案 0 :(得分:1)
您的第一个;
子句末尾有一个WHERE
,它正在切断您的NOT IN
条款。将其移至查询的末尾:
select c.company_id,c.company_name, pe.pe_relationship, opt.oo_type
from pub_entity pe
inner join company c on c.company_id = pe.pe_company_id
inner join opt_out opt on opt.oo_company_id=c.company_id
where pe.pe_pn_id in (SELECT pn_id FROM pub_notice WHERE pn_company_id=2523)
and opt.oo_type not in ('image','iframe');