简体   繁体   中英

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.

For example,

Table A has the columns: IP,Host,App

Table B has the columns: IP,Datacenter,Server,Model,Last_Updated

How do I compare the IP column between the two tables to get the differences?

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.

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.

you mean you want to get all IPs in table A that are not in table B?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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