在SQL中使用WHERE和AND

时间:2017-02-15 22:45:16

标签: sql

我正在尝试运行此查询

select from_ from uploaded_emails1
where uploaded_emails1.from_ != 'test@email_domain.com'
and uploaded_emails1.from_ not in candidate_emails1.email

但我收到错误No such table candidate_emails1.email。但是如果我运行select email from candidate_emails1它运行正常。

我做错了什么?

3 个答案:

答案 0 :(得分:2)

  

别名candidate_emails1未在您的sql中定义

select from_ from uploaded_emails1
where uploaded_emails1.from_ != 'test@email_domain.com'
and uploaded_emails1.from_ not in(select emails from  candidate_emails1)

答案 1 :(得分:0)

尝试:

SELECT from_ FROM uploaded_emails1, candidate_emails1
WHERE uploaded_emails1.from_ != 'test@email_domain.com'
AND uploaded_emails1.from_ != candidate_emails1.email

答案 2 :(得分:0)

通过使用NOT IN子句或NOT EXISTS子句,有两种方法可以做到这一点:

SELECT
    from_
FROM uploaded_emails1
WHERE uploaded_emails1.from_ != 'test@email_domain.com'
AND NOT EXISTS (
    SELECT *
    FROM candidate_emails1
    WHERE candidate_emails1.email = uploaded_emails1.from_
);

...或...

SELECT
    from_
FROM uploaded_emails1
WHERE uploaded_emails1.from_ != 'test@email_domain.com'
AND uploaded_emails1.from_ NOT IN (
    SELECT email
    FROM candidate_emails1
);