|
|
Question : Copy all distinct data from one table to another
|
|
I've got two tables, identical in terms of fields. I need to copy all data that's distinct on three fields (three fields make up the primary key). typeID, activity and requiredTypeID.
Any ideas?
Thanks, Xtianu
|
Answer : Copy all distinct data from one table to another
|
|
INSERT INTO table2 (typeID, activity, requiredTypeID, col4, col5) SELECT t1.typeID, t1.activity, t1.requiredTypeID, t1.col4, t1.col5 FROM table1 t1 LEFT OUTER JOIN table2 t2 ON t2.typeID = t1.typeID AND t2.activity = t1.activity AND t2.requiredTypeID = t1.requiredTypeID WHERE t2.typeID IS NULL
|
|
|
|
|