SQL将数据从一列复制到另一列指定的表

时间:2022-06-20 20:10:18

i have two tables name called by order and order_product, both tables have a column same name model, order_product model column have lots of data, but order model empty field.

我有两个表名,由order和order_product调用,两个表都有一个列相同的名称模型,order_product模型列有很多数据,但是order模型是空字段。

i want copy model data from table order_product to model table order, how can i do this.?

我想要将模型数据从表order_product复制到模型表订单,我怎么做呢?

i tried some SQL query, but the result not like really what i want, its look all field will be duplicate...

我尝试了一些SQL查询,但结果并不是我想要的,它的所有字段都是重复的…

INSERT INTO `order` (model) SELECT (model) FROM `order_product`

3 个解决方案

#1


1  

INSERT INTO order (model)
SELECT model FROM order_product
WHERE 'some field' = (some condition)

#2


4  

Try to use DISTINCT to eliminate duplicate rows in the SELECT clause like so:

尝试使用不同的方法消除SELECT子句中的重复行:

INSERT INTO `order` (model) 
SELECT DISTINCT model FROM `order_product`;

SQL Fiddle Demo

#3


1  

INSERT INTO table1 ( column1 )
SELECT  col1
FROM    table2

this should work for ur question?? kindly let me know what is the desired output u except such that i will update the answer

这对你的问题有用吗??请让我知道你想要的输出u是什么,这样我才能更新答案

By seeing ur comments

看到你的评论

INSERT INTO table1 ( column1 )
SELECT distinct(col1)
FROM    table2

#1


1  

INSERT INTO order (model)
SELECT model FROM order_product
WHERE 'some field' = (some condition)

#2


4  

Try to use DISTINCT to eliminate duplicate rows in the SELECT clause like so:

尝试使用不同的方法消除SELECT子句中的重复行:

INSERT INTO `order` (model) 
SELECT DISTINCT model FROM `order_product`;

SQL Fiddle Demo

#3


1  

INSERT INTO table1 ( column1 )
SELECT  col1
FROM    table2

this should work for ur question?? kindly let me know what is the desired output u except such that i will update the answer

这对你的问题有用吗??请让我知道你想要的输出u是什么,这样我才能更新答案

By seeing ur comments

看到你的评论

INSERT INTO table1 ( column1 )
SELECT distinct(col1)
FROM    table2