MySQL Query返回奇怪的结果

时间:2015-07-15 19:25:13

标签: mysql sql

我有以下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列中,我仍然会收到imageiframe个结果。

opt.oo_type的类型为enum('image','iframe','other')任何人都可以告诉我为什么我仍然会得到这些结果?

1 个答案:

答案 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');