【问题标题】:SQLite select in where clauseSQLite 在 where 子句中选择
【发布时间】:2013-05-28 08:16:44
【问题描述】:

我有一个返回列表代码的查询。

SELECT cc.code FROM lotw l
                 LEFT JOIN CountryCode AS cc on cc.code = l.dxcc 
                 WHERE cc.code > ''  GROUP BY cc.Country

这很好用。现在我需要在国家表中查询不在从上述查询发回的列表中的代码。所以我尝试了以下方法:

SELECT code,country from CountryCode 
WHERE code !=  (SELECT cc.code FROM lotw l
                 LEFT JOIN CountryCode AS cc on cc.code = l.dxcc 
                 WHERE cc.code > ''  GROUP BY cc.Country)

但是我从国家代码中取回了所有记录?我想要所有代码不在子查询中的国家?

【问题讨论】:

  • 就是这样!如果您将其作为答案,我会将其标记为答案,谢谢

标签: sqlite select where-clause


【解决方案1】:

你需要使用NOT IN而不是!=;

SELECT code,country from CountryCode 
WHERE code NOT IN (SELECT cc.code FROM lotw l
                   LEFT JOIN CountryCode AS cc on cc.code = l.dxcc 
                   WHERE cc.code > ''  GROUP BY cc.Country)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-25
    • 1970-01-01
    相关资源
    最近更新 更多