高级 MySql 查询:使用另一个表中的信息更新表

Advanced MySql Query: Update table with info from another table(高级 MySql 查询:使用另一个表中的信息更新表)
本文介绍了高级 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 查询:使用另一个表中的信息更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)