简体   繁体   English

用sql中另一个表中的产品ID替换产品代码

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

相关问题 获取产品ID,然后从另一个表中获取子类别和产品标题 - Getting ID of product then getting subcategory and product titles from another table SQL从一个表中选择品牌,如果另一个表具有该品牌的产品 - SQL to select brand from a table, if another table has a product with that brand 从产品类型表中选择产品ID,但通过演绎显示 - Select product id from product genre table but show by exect macting mysql-通过id从一个表中选择一个产品,然后从另一个表中选择其关联的图像 - mysql- select a product from one table by id, then its associated images from another table MySql:从另一个表获取产品的名称 - MySql: Get name of a product from another table Laravel,如果将商品ID存储到购物车中,如何从商品表中获取商品名称 - Laravel, How to get product name from product table if the product id stored into Cart (Laravel/PHP) SQL 从表中选择与数组中的 product_id 和 variation_id 匹配的所有订单的查询 - (Laravel/PHP) SQL Query that selects all orders from table that matches product_id and variation_id in array 如果添加了其他产品,则不允许从 WooCommerce 购物车中删除具有特定 ID 的产品 - Disallow to remove a product with a specific ID from WooCommerce cart if another product is added 如何从包含 laravel 中 product_id 的订单表中获取产品名称? - How to fetch product name from orders table which contain product_id in laravel? 我想显示具有相同 product_id laravel 的另一个表中的 product_name - i want to display the product_name from the other table that has the same product_id laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM