mysql - Sql (mariadb) 删除重复名称并更新其他表

标签 mysql sql mariadb

我想从表:attribute_lang 中删除重复的名称。 另外,使用 id_attribute 更新 Product_attribute 表。 请帮忙解决sql问题。

表:attribute_lang

id_attribute,name
1,15
2,16 
3,15 -> remove 
4,16 -> remove 

表:产品属性

id_product,id_attribute
12,1
13,2
14,3 -> change id_attribute to 1 
15,4 -> change id_attribute to 2

最佳答案

首先您必须更新您的产品

update product_attribute
set id_attributte = 2
where id_product = 15

update product_attribute
set id_attributte = 1
where id_product = 14

然后删除重复的

delete from attribute_lang
where id_atributte in(3,4)

关于mysql - Sql (mariadb) 删除重复名称并更新其他表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49706872/

相关文章:

sql - 更新大型表上的行的最高效方法

php - 如果非主键列重复,则更新 MySQL 表,否则插入?

mysql - 在oracle中的同一列中交换名称

SQL Server - 通过标志总结日期

sql - Oracle中是否需要 'as'关键字来定义别名?

mysql - 如何限定 CASE 表达式中的条件(类似于 WHERE 子句)

mysql - WordPress:将 MySQL 数据库导入到 MariaDB

MySQL GROUP BY 列并显示不同列中的值

mysql - 外键错误: MySQL ERROR 1005 (HY000): Can't create table

MySQL 5.1/MariaDB 5.5 临时表行为更改