简体   繁体   English

比较两个不同表中的列

[英]Compare a column in two different tables

Say I have two tables, Table A and Table B, and I want to compare a certain column. 假设我有两个表,表A和表B,我想比较某个列。

For example, 例如,

Table A has the columns: IP,Host,App 表A包含列:IP,主机,应用程序

Table B has the columns: IP,Datacenter,Server,Model,Last_Updated 表B包含以下列:IP,数据中心,服务器,模型,Last_Updated

How do I compare the IP column between the two tables to get the differences? 如何比较两个表之间的IP列以获得差异?

I know if the tables have the same columns I can use a union and 'minus' to get the differences but I wasn't able to figure out a way if the tables have different columns. 我知道如果表有相同的列我可以使用union和'减'来获得差异但是如果表有不同的列我就无法找到方法。

Thanks! 谢谢!

SELECT  *
FROM    A
FULL JOIN
        B
ON      a.IP = b.IP
WHERE   a.IP IS NULL OR b.IP IS NULL

This will output all columns from non-matching rows in both tables, with NULLs on either side. 这将输出两个表中不匹配行的所有列,两侧都有NULL。

you mean you want to get all IPs in table A that are not in table B? 你的意思是你想要获得表A中不在表B中的所有IP?

select IP from table A
MINUS
select IP from table B

Did I understand the question correctly? 我是否正确理解了这个问题?

select distinct column_A FROM table_1 where column_A not in (SELECT column_A FROM table_2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM