有效地比较两个表中的列

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了有效地比较两个表中的列相关的知识,希望对你有一定的参考价值。

This compares selected columns between 2 tables that you think might have differences. It lists the rows and values that are different between the two sources

You can add WHERE clauses as appropriate. You could also use this to compare the results of two queries.

This is from Tom Kyte (www.asktom.com). I can't say I understand exactly how it works, but it's much faster than other methods I've seen. It has the advantage of only looking through each table once.
  1. SELECT COUNT(src1) AS in_old_addresses,
  2. COUNT(src2) AS in_new_addresses,
  3. first_name,
  4. last_name,
  5. city
  6. FROM (SELECT first_name, last_name, city, 1 AS src1, TO_NUMBER(NULL) AS src2
  7. FROM old_addresses
  8. SELECT first_name, last_name, city, TO_NUMBER(NULL) AS src1, 2 AS src2 FROM new_addresses)
  9. GROUP BY first_name, last_name, city
  10. HAVING COUNT(src1) <> COUNT(src2);

以上是关于有效地比较两个表中的列的主要内容,如果未能解决你的问题,请参考以下文章

将表中的列与 hive 中另一个表的列进行比较

如何比较两个表的列并将值插入到基于 SQL Server 中存储过程中的比较的新表中

将主表与另一个表中的所有记录进行比较,以得出主表的列值

如何根据与另一个表中的值的比较来更新列

将表中的一列替换为不同表中的列并选择 *

mySQL在触发器中比较两个不同的列值