简体   繁体   English

在 SQL 中,使用主键连接两个表后,如何仅返回表之间另一列中的值不同的行

[英]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.

相关问题 连接两个表后返回不匹配的行 - Return not matching rows after joining two tables 如何在使用内部联接合并两个表时将列设置为PRIMARY KEY(两个联接表中没有主键) - How to set a column to PRIMARY KEY while merging two tables using inner join?(there is no primary key in the two joining tables) 连接两个表,其中表1与表2具有相同的主键 - Joining two tables where table 1 has same primary key with table 2 如何从两个表中查询匹配表中的外键和另一个表中的主键 - How do I query from two tables matching the foreign key from table with the primary key from another 在 Rails 中加入两个表,但不在主键上 - Joining two tables in Rails but not on the primary key 如何合并 MySQL 中的两个表以及表 1 为主的表 - How do I merge two tables in MySQL and where table 1 is primary 在SQL中联接表,其中新列名基于另一列的联接表值 - Joining tables in SQL where new column name is based on joined table value from another column mysql连接两个表以获取某些列是特定值的地方 - mysql joining two tables to get where certain column is a specific value 我需要在两个表之间的sql外键列中插入什么 - What do I have to insert in sql foreign key column between two tables 连接两个表时WHERE子句不显示所有行? 我需要左连接吗? - WHERE clause not showing all rows when joining two tables? Do I need a left join?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM