无法想象这个简单的sql。 crm_contact_id在整个表中使用相同的联系人ID进行更新。我试图让它等于我在执行select时查询等于的内容。
update events set crm_contact_id = c.id
from events as evts
inner join crm2.crm_retail_lead l on l.lead_number = evts.old_lead_number
inner join crm_contacts c on c.old_contact_id = l.contact_id
谢谢你看看。
答案 0 :(得分:2)
当你这样做时:
UPDATE events... FROM events as evts JOIN [other tables]
您将获得 events 表的两个不相关的实例。 这可能不是你想要的。固定版本看起来像这样:
update events evts set crm_contact_id = c.id
from crm2.crm_retail_lead l
inner join crm_contacts c on c.old_contact_id = l.contact_id
where l.lead_number = evts.old_lead_number
答案 1 :(得分:0)
您尚未在查询中放置任何WHERE
子句.....使用where
子句进行查询
update events set crm_contact_id = c.id
from events as evts
inner join crm2.crm_retail_lead l on l.lead_number = evts.old_lead_number
inner join crm_contacts c on c.old_contact_id = l.contact_id
WHERE column_name='value'