需要从两个表列中选择不重复的值 [英] Need to select the non-duplicate values from two table columns

查看:25
本文介绍了需要从两个表列中选择不重复的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张带有城市名称的表格.我想根据第二个表检查第一个表,如果第一个表在第二个表中不包含城市名称,则选择它进行显示.因此,如果城市在两个表中,则不要显示它.

I have two tables with city names in them. I want to check the first table against the second table and if the first table does not contain a city name in the second table then select it to display. So if the city is in both tables, then do not display it.

我知道我可以这样做来找到匹配的:

I know that I can do this to find the ones that match:

WHERE table1.city=table2.city

但是当我尝试将其用于不匹配的事物时:

But when I try to use this for things that dont match:

Where table1.city!=table2.city

我仍然得到匹配的城市.

I still get the cities that match.

推荐答案

SELECT `city_name` 
FROM `first_table`
WHERE `city_name` NOT IN (SELECT `city_name` FROM `second_table`)

将从第一个表中选择不在第二个表中的城市名称.

Will select city names from the first table that are not in second table.

这篇关于需要从两个表列中选择不重复的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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