Advanced MySql Query: Update table with info from another table(高级 MySql 查询:使用另一个表中的信息更新表)
问题描述
我想用另一个表中的数据更新 mySql 中的一个表.
I would like to update a table in mySql with data from another table.
我有两个表people"和business".人员表通过名为business_id"的列链接到业务表.
I have two tables "people" and "business". The people table is linked to the business table by a column called "business_id".
必要的表结构,主键加星号(表:列):人员:*business_id、*sort_order、电子邮件业务:*business_id,电子邮件
The necessary table structure, primary key is starred (Table: columns): People: *business_id, *sort_order, email Business: *business_id, email
我想用来自 people 表的电子邮件更新业务表的电子邮件列,类似这样(我知道我在这里遗漏了一些东西):
I would like to update the business table email column with the email from the people table, something like this (I know I am missing something here):
UPDATE business b SET email = (SELECT email from People p where p.business_id = b.business_id AND sort_order = '1') WHERE b.email = '';
这有意义吗?可能吗?
推荐答案
UPDATE business b, people p
SET b.email = p.email
WHERE b.business_id = p.business_id
AND p.sort_order = '1'
AND b.email = ''
这篇关于高级 MySql 查询:使用另一个表中的信息更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:高级 MySql 查询:使用另一个表中的信息更新表


基础教程推荐
- 带更新的 sqlite CTE 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01