我有以下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')
谁能告诉我为什么我仍然得到这些结果? 最佳答案
第一个;
子句的末尾有一个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');
关于mysql - MySQL查询返回奇怪的结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31439307/