[英]In SQL after joining two tables with a primary key how do I return only the rows where a value in another column differs between the tables
I have code reading我有代码阅读
SELECT * FROM table1 A JOIN table2 B ON A.id = B.id WHERE_____?
The "id"s in table 1 and 2 are the same but some of the other values in different columns may differ.表 1 和表 2 中的“id”相同,但不同列中的其他一些值可能不同。 How do I search every column and return only the rows where there is a difference between table 1 and 2. For values that differ will it return the row from table 1?
如何搜索每一列并仅返回表 1 和表 2 之间存在差异的行。对于不同的值,它将返回表 1 中的行吗? Thank you.
谢谢你。
You would use:你会使用:
where a.col1 <> b.col1 or a.col2 <> b.col2 or . . .
or, if you need to take NULL
s into account:或者,如果您需要考虑
NULL
:
where not (a.col1 <=> b.col1 and a.col2 <=> b.col2 and . . . )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.