mysql - 用另一个表的另一列的数据更新一列

标签 mysql sql

我有两个表

  1. 标题_下载
  2. title_history

目前我将 idtitle_history 保存在 titles_downloads 中作为一列。 title_history 有一个与 idtitle_history 不同的列 idtitle。

我想将我的 titles_downloads 表中的 idtitle_history 更改为 idtitle

title_history 表的示例数据

       idtitle_history                 idtitle
            1                             160
            2                             210
            3                             345

标题_下载

       iddownloads                      idtitle_history
            1                              1
            2                              2
            3                              3

我想把这个表中的idtitle替换成160,210,345 ...

谢谢

最佳答案

尝试

update titles_downloads
inner join title_history 
on title_history.idtitle_history  = titles_downloads.idtitle_history 
set idtitle_history = title_history.idtitle

关于mysql - 用另一个表的另一列的数据更新一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11326708/

相关文章:

PHP 在下一个按钮上逐行获取结果

mysql - 如何使用地址或电话号码关联 parent /子女关系中的帐户?

python - 加快 MySQL 更新/插入语句

MySQL:删除主键会删除唯一约束和/或索引吗?

MySQL JOIN 条件查询

MySQL:使用命名值和位运算符更新 SET 字段

sql - 如何找到数据库中哪一行使用的空间最多?

mysql - 在 2 个表上使用 Count 和 SUM 函数的 SQL 帮助

sql - 获取所有引用(通过外键)表中特定行的行

mysql - 每个user_id的时间总和