简体   繁体   English

SQL:如何使用 MariaDB 中的连接使用来自另一个表的数据更新一个表

[英]SQL: how to update one table with the data from another using join in MariaDB

I am pretty new to SQL.我对 SQL 很陌生。 I am trying to update one table with the data from another.我正在尝试用另一个表的数据更新一个表。

Table1: albums表 1:专辑

album_id
user_id   -   correct value

Table2: images表 2:图像

image_id
album_id
user_id  -  wrong value

I need to update images.user_id with data from albums.user_id where albums.album_id = images.album_id我需要使用来自albums.user_id的数据更新images.user_id ,其中albums.album_id = images.album_id

You can use an update / join :您可以使用update / join

update images i join
       albums a
       using (album_id)
     set i.user_id = a.user_id;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用另一个表中的数据更新sql中的表? - How to update a table in sql using data from another one? 使用连接查询(oracle sql)时如何查看一个表中的所有数据并在另一个表上过滤 - How to see all data from one table and filtered on another, when using a join query (oracle sql) 使用sql server将数据从一张表更新到另一张表 - update data from one table to another using sql server postgreSQL:使用JOIN和UPDATE用来自另一个表的数据更新一个表 - postgreSQL: use JOIN and UPDATE to update one table with data from another 使用join update或插入SQL Server从另一个表插入一个表 - insert into one table from another table using join update or insert SQL server SQL 连接以更新一个表并参考另一个表 - SQL join to update one table with reference to another MariaDB - 如何使用IF / ELSE从另一个表中添加(JOIN)另一列 - MariaDB - How to add(JOIN) one more column from another table with IF/ELSE 如何将2个sql行从一个表连接到另一个表 - How to join 2 sql rows from one table into one in another 如何使用 SQL 中的事务将数据从一个表插入到另一个表? - How to insert data from one table to another using transactions in SQL? SQL 更新 - 如何使用另一个表更新一个表中的列? - SQL UPDATE - How to update a column from one table using another table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM