There are two tables with identical structure.
Let's assume the number of rows in both is equal.
how would you check if all rows are equal? Is there any faster way than comparing every column value of a given row with the same id in both tables?
Try this:
SELECT * FROM table1
EXCEPT
SELECT * FROM table2
If anything is returned then they are not equal.
Abe's answer is correct, but only if they have the same number of rows. (I misread the question when I wrote my original response "condemning" his answer.) If table1 may be a subset of (a larger) table2 or vice versa, I would try:
if
(
not exists ( select * from table1
except
select * from table2
)
and
not exists ( select * from table2
except
select * from table1
)
)
This gives true if they are the same, and false if they are different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With