[英]Replace a product code with the product id from another table in sql
the previous developer has done a wrong practice in a sql database with phpmyadmin, which is creating a problem of duplicate contents. 以前的开发人员使用phpmyadmin在sql数据库中执行了错误的操作,这造成了重复内容的问题。
Correct way: 正确方法:
table 1 表格1
ORDERS 命令
id_order id_order
id_product id_product
table 2 表2
PRODUCTS 产品展示
id_product id_product
internal_product_code internal_product_code
——— ———
Wrong way: 错误的方法:
table 1 表格1
ORDERS 命令
id_order id_order
internal_product_code internal_product_code
table 2 表2
PRODUCTS 产品展示
id_product id_product
internal_product_code internal_product_code
Unfortunately, the internal_product_code is NOT always unique**, while id_product and id_order are always unique. 不幸的是, internal_product_code并不总是唯一的**,而id_product和id_order总是唯一的。 So today my client has get the first duplicate data content, because there's two products with different id_product but same internal_product_code.
因此,今天,我的客户得到了第一个重复的数据内容,因为有两个产品具有不同的id_product但具有相同的internal_product_code。
** the same internal_product_code due to a very similar specs (this is another bad practice)** **由于规格非常相似,因此使用相同的internal_product_code(这是另一种不好的做法)**
Is there any way to replace table1.internal_product_code with table2.id_product in order to follow the correct way? 有什么方法可以用table2.id_product替换table1.internal_product_code以便遵循正确的方法? I need to do it in the database (after a strong backup).
我需要在数据库中进行此操作(经过严格的备份之后)。
Thanks to all 谢谢大家
UPDATE orders SET products = (SELECT orders.id_order FROM products WHERE orders.id_product = products.internal_product_code LIMIT 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.