简体   繁体   English

MySQL从两个不同的表中查找重复项

[英]Mysql Find Duplicates from two different tables

I have one contacts table with following fields : 我有一个具有以下字段的联系人表

id,
first_name,
last_name,

Also one more email_contacts table with following fields: 还有一个带有以下字段的email_contacts表

id,
email_address_id,
bean_id,

bean_id is the unique id from contacts table and email_address_id is unique id from other third email table . bean_idcontacts table的唯一ID, email_address_id是其他第三电子邮件表中的唯一ID。

I want to find duplicates from contacts table along with their respective emails. 我想从联系人表以及他们各自的电子邮件中找到重复项。

Perhaps I'm not seeing the whole problem, but it would appear that contacts.id is a primary key, and email_contacts.bean_id is a foreign key. 也许我没有看到问题的全部,但它会出现contacts.id是一个主键,并且email_contacts.bean_id是一个外键。

If that's the case, then SELECT contacts.first_name , contacts.last_name , and email_contacts.email_id with a JOIN on contacts.id = email_contacts.bean_id . 如果是这样的话,那么选择contacts.first_namecontacts.last_name ,并email_contacts.email_id与上使用JOIN contacts.id = email_contacts.bean_id

Let me know if this answer is in the right direction, and then we can address the question of duplicate records. 让我知道此答案是否正确,然后我们可以解决重复记录的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM