Db2 – REPLACE INTO SELECT from table

db2replaceselect

Is there a way in DB2 to replace the entire table with just selected rows from the same table ?

Something like REPLACE into tableName select * from tableName where col1='a';
(I can export the selected rows, delete the entire table and load/import again, but I want to avoid these steps and use a single query).

Original table

col1   col2  
 a      0 <-- replace all rows and replace with just col1 = 'a'  
 a      1 <-- col1='a'  
 b      2  
 c      3  

Desired resultant table

col1  col2  
 a      0  
 a      1  

Best Answer

If you are doing SQL, then you probably would need to do a TRUNCATE/DELETE on the table and then INSERT into.

If you are using LOAD and/or IMPORT, they both have options for clearing the table before getting data into the table.