MySQL Update Subset Having

感情迁移 提交于 2019-12-05 03:51:21
santiagobasulto

The simplest solution:

UPDATE contacts_domains cd SET cd.dominant = 1
WHERE cd.id IN (
SELECT dominant_id
FROM contacts_domains
GROUP BY domain_id
HAVING COUNT(contact_id) = 1
)

Edited.

I had problem like this. Try with joining with table make with select:

UPDATE contacts_domains cd, 
 (SELECT id FROM contacts_domains GROUP BY domain_id
   HAVING COUNT(contact_id) = 1) AS cdtmp
SET cd.dominant = 1
WHERE cd.id = cdtmp.id

Hope it will help

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!