DB2 graphic  QMF Version 8

Copying rows from one table into another using SQL statements

You can use an insert query to copy certain rows and columns from an existing table into another table.

You can add the rows to an existing table, or you can specify a new table name and create a new table to contain the rows you specify.

For example, the following insert query adds the ID number, name, department, and job columns for all employees in department 38 in the Q.STAFF table to the MYSTAFF table:

 INSERT INTO MYSTAFF (ID, NAME, DEPT, JOB)
 SELECT ID, NAME, DEPT, JOB
   FROM Q.STAFF
   WHERE DEPT = 38

After running this query, QMF adds five new rows to the MYSTAFF table. For these employees, the YEARS, SALARY, and COMM columns contain null values, because QMF does not select these columns in the query. If you want to include all the data for a row, you must select all the columns in the table.


Go to the previous page Go to the next page

Downloads | Library | Support | Support Policy | Terms of use | Feedback
Copyright IBM Corporation 1982,2004 Copyright IBM Corporation 1982, 2004
timestamp Last updated: March, 2004