AmEng
AmEng

Reputation: 1

Comparing Table 1 with Table 2 in Netezza where Table 1 has million records

I'm new to SQL and trying the examples but didn't find it as per my requirement. I would be happy if any pro can able to answer.

I have a Table A with 150 columns and millions of records. I need to compare the Table A with Table B(Both Table A and B is in Netteza).

I need a SQL query which can compare the both tables A and B record by record and give me results if there is discrepancy in the record of Table B.

Table A

FirstName LastName ZipCode
Gary      Martin   500020
John      Mills    788802

Table B

FirstName LastName ZipCode
Gary      Martin   500020
John      Mill     788802

Expected to get results like this:

FirstName LastName ZipCode   FirstName LastName ZipCode 
John      Mills    788802    John      Mill     788802

Upvotes: 0

Views: 2635

Answers (1)

MightyRearranger
MightyRearranger

Reputation: 128

Are the table structures exactly the same? If so you could potentially use Set Operators, though the performance might not be the best. Something along the lines of:

Select * 
  from (Select * From TableA
       MINUS
       Select * from TableB) A
       Join
       (select * from TableB
       MINUS
       Select * from TableA) ON *common unique field if there is one*

Each of the MINUS sub queries will give you the records in the First table which an exact match can't be found for in the second. If there's a common unique identifier in the two tables then you could then join the results of the two sub-queries to get the result you're expecting.

Upvotes: 1

Related Questions