MySQL更新子集有
我有三个表:contacts、domains 和contacts_domains,它们形成多对多关系。
我想运行一个更新 contact_domains 表的查询,但仅限于只有一个联系人的域。
我知道如何选择我感兴趣的行,但不知道如何更新它们。
SELECT domain_id, contact_id, dominant
FROM contacts_domains
GROUP BY domain_id
HAVING COUNT(contact_id) = 1
我想为所有这些结果设置contacts_domains.dominant = 1。
谢谢!
I have three tables: contacts, domains, and contacts_domains, which form a many-to-many relationship.
I would like to run a query that updates the contacts_domains table, but only for domains that have exactly one contact.
I know how to SELECT the rows I'm interested in, but not how to UPDATE them.
SELECT domain_id, contact_id, dominant
FROM contacts_domains
GROUP BY domain_id
HAVING COUNT(contact_id) = 1
I want to set contacts_domains.dominant = 1 for all these results.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有这样的问题。尝试使用 select 与 table make 连接:
希望有帮助
I had problem like this. Try with joining with table make with select:
Hope it will help