如何获取仅包含列2的给定值的列1的值? [英] How to fetch values of column 1 that contain only the given value of column 2?

查看:70
本文介绍了如何获取仅包含列2的给定值的列1的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择出现在墨西哥而不是其他任何国家的名字。

I want to select names that only appear in Mexico and not in any other country.

Country      |  Name      
-------------|------------
Mexico       |  Vallejo
Mexico       |  Rachel
United States|  Rachel
UK           |  Rachel
Australia    |  Rachel
Mexico       |  Amy
Canada       |  Amy 
Mexico       |  Annette
Mexico       |  Jennifer
Swahili      |  Jennifer 
Mexico       |  Benedict 

正确的查询将仅返回以下名称。

The correct query would only return the following names.

Name      
---------
Annette
Benedict
Vallejo

有什么想法吗?我不确定这是否是DISTINCT和WHERE条件的混合。

Any ideas? I'm not sure if this might be a mix of DISTINCT and WHERE conditions.

推荐答案

我认为您想要类似的东西

I think you want something like

SELECT Name
FROM <table>
WHERE Country = 'Mexico'
AND Name NOT IN (
    SELECT Name
    FROM <table>
    WHERE Country <> 'Mexico')

这篇关于如何获取仅包含列2的给定值的列1的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆