SQL如何比较两个不同表中的两个列 [英] SQL how to compare two columns from two different tables

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

问题描述

我有两个表,其中表1包含4列,而表2包含8列.我想将table1中的两列与table2中的两列进行比较.

I have two tables, in which table 1 contains 4 columns while table 2 contains 8 columns. I have two columns in table1 that I want to compare them with two columns in table2.

Table 1 have column1 and column2 (that needs to be compared)
Table 2 have column6 and column7 (that needs to be compared) 

我需要比较两列的组合.我试图做下面的查询,但是没有用

I need to compare the combination of the two columns. I tried to do the below query however it doesn't work

Select * from table1 
where column1, column2 NOT IN (Select column6, column7 from table2)

如何比较两个表中的两列?

How can I compare the two columns in the the two tables?

推荐答案

尝试使用减号语句.这将为您提供来自table1的第一条select语句的结果,而不是table2的第二条select语句中的结果.

Try a minus statement. This will give you any results from the first select statement of table1 that aren't in the second select statement on table2.

select column1, column2 from table1
minus
select column6, column7 from table2

这篇关于SQL如何比较两个不同表中的两个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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