mans
mans

Reputation: 1087

SQL copy data from one column to another table specified column

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.

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

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

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

Upvotes: 4

Views: 11493

Answers (3)

Dhruv
Dhruv

Reputation: 1089

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

Upvotes: 3

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79929

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

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

SQL Fiddle Demo

Upvotes: 5

Ghostman
Ghostman

Reputation: 6114

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

By seeing ur comments

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

Upvotes: 1

Related Questions