[英]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.