我有两个数据库,每个数据库都有联系人表。我想从冗余数据库中找出主数据库中存在哪些联系人。主数据库是sugarcrm。我要冗余的是hdb。我有以下不工作的查询
SELECT c.id, c.first_name, c.last_name
from `sugarcrm`.`contacts` c
left join `hdb`.`contacts` as cl
ON cl.lastname = c.last_name
left join `hdb`.`contacts` as cf
on cf.firstname = c.first_name
limit 0, 10000
我在 sugacrm.contacts 中共有 10187 条记录,在 hdb.contatcs 中共有 8619 条记录。
我试过这个
SELECT c.id, c.first_name, c.last_name
from `sugarcrm`.`contacts` c
where not exists
(select * from `hdb`.`contacts`
where firstname != first_name and lastname != last_name
)
limit 0, 10000
返回 14 条记录
我想包括与电子邮件地址的比较,但我的查询不起作用。在 sugarcrm 中链接电子邮件地址如下
email_address 表有 id email_addr_bean_rel 有 email id 和 contact id
SELECT
c.id,
c.first_name,
c.last_name
FROM `sugarcrm`.`contacts` c, `sugarcrm`.`email_addresses` e, `sugarcrm`.`email_addr_bean_rel` er
LEFT JOIN `hdb`.`contacts` as cl
ON cl.lastname = c.last_name
AND cl.firstname = c.first_name
AND cl.email = e.email_address
inner join `sugarcrm`.`contacts`
on er.bean_id = `sugarcrm`.`contacts`.id
inner join `sugarcrm`.`email_addr_bean_rel`
on e.id = er.email_address_id
limit 0,100000
我决定使用电子邮件,使用navicat管理获得以下信息
SELECT
sugarcrm.email_addresses.email_address
FROM
sugarcrm.contacts
INNER JOIN sugarcrm.email_addr_bean_rel ON sugarcrm.contacts.id = sugarcrm.email_addr_bean_rel.bean_id
INNER JOIN sugarcrm.email_addresses ON sugarcrm.email_addresses.id = sugarcrm.email_addr_bean_rel.email_address_id
INNER JOIN hdb.contacts ON sugarcrm.email_addresses.email_address = hdb.contacts.EMAIL
LIMIT 0, 100000