Categories
SQL

SQL : Table Column Comparison

SQL : Table Column Comparison

The following SQL will perform a one way comparison of a column from one table with another. Any listed items do not exist in the second table:

— Identify if values in Table1 exist in Table2
Select DealerID
FROM Table1
WHERE NOT EXISTS
(SELECT 1 FROM Table2
WHERE Table1.DealerID = Table2.DealerID

This can be extended to multiple columns:

Select DealerID, Name
FROM TABLE1
WHERE NOT EXISTS
(SELECT 1 FROM TABLE2
WHERE Table1.DealerID = Table2.DealerID
AND Table1.Name = Table2.Name
)

Leave a Reply

Your email address will not be published. Required fields are marked *