Thorsten Niehues
Thorsten Niehues

Reputation: 14452

Database Table Content Comparison

We Use SAP HANA as database.

How can I compare if two tables have the same content?

I already did a comparison of the primary key using SQL:

select COUNT (*) from Schema.table1;
select COUNT (*) from Schema.table2;
select COUNT (*) 
   from Schema.table1 p
     join schema.table2 r
    on p.keyPart1 = r.keyPart1 
    and p.keyPart2 = r.keyPart2 
    and p.keyPart3 = r.keypart3;

So I compared the rows of both tables and of the join. All row counts are the same.

But I still don't know if the content of all rows are exactly the same. It could be that one ore more cells of a non-key column is deviating.

I thought about putting all columns in the join Statement. But that did not feel right.

Upvotes: 0

Views: 4056

Answers (1)

Shidai
Shidai

Reputation: 227

You might want to use except

SELECT * FROM A
EXCEPT
SELECT * FROM B;

SELECT * FROM B
EXCEPT
SELECT * FROM A;

Upvotes: 2

Related Questions