Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 从表联接中获取所有字段上不完全匹配的所有记录_Sql_Database_Tsql - Fatal编程技术网

Sql 从表联接中获取所有字段上不完全匹配的所有记录

Sql 从表联接中获取所有字段上不完全匹配的所有记录,sql,database,tsql,Sql,Database,Tsql,我遇到了这样一种情况,我用一些第三方实用程序更新了一个表,我想将它与原始表进行比较,确保它进行了正确的更新和插入 所以,我想这样做,但我不太懂语法: SELECT * FROM table1 AS a RIGHT OUTER JOIN table2 AS b WHERE <there is some difference between the row from a and the row from b, regardless of which column it's i

我遇到了这样一种情况,我用一些第三方实用程序更新了一个表,我想将它与原始表进行比较,确保它进行了正确的更新和插入

所以,我想这样做,但我不太懂语法:

SELECT * FROM table1 AS a RIGHT OUTER JOIN table2 AS b WHERE 
    <there is some difference between the row from a and the row from b,
    regardless of which column it's in>
如何比较所有字段而不必逐个显式写入


编辑:我还应该提到,我在表的副本中进行了更新,因此假设是原始的,是更新的副本。

您应该使用减号查询

select field1, field2, field3, field4
  from table1
 except 
select field1, field2, field3, field4
  from table2

这将返回表1中在表2中找不到其数据字段1、字段2、字段3、字段4的所有行。Warining:相反,如果您还需要表2中而不是表1中的数据,那么您必须执行第二次查询,执行表2减去表1。

您应该使用的是减号查询

select field1, field2, field3, field4
  from table1
 except 
select field1, field2, field3, field4
  from table2

这将返回表1中在表2中找不到其数据字段1、字段2、字段3、字段4的所有行。警告:这不是另一种方式,因此如果您还需要表2中而不是表1中的数据,那么您必须执行第二次查询,执行表2减去表1。

TSQL中的减去关系运算符与标准SQL不同。@onedaywhen抱歉,我来自Oracle开发:TSQL中的负关系运算符与标准SQL不同。@有一天,对不起,我来自Oracle开发: