SQL — SELECT Into a New Table

 

In BBj 7.0 and higher, developers can dump the contents of a SELECT statement into a new table. Developers use this most often for creating a temporary table that the application uses for a short time.

To create a table from the results of a SELECT statement, use the SELECT…INTO syntax. The following example creates a new table named NEW_TEMP_TABLE with three columns (COL1, COL2, COL3) and populates it with the results of the SELECT statement:

SELECT col1, col2, col3 INTO new_temp_table FROM mytable

The new table is a normal table that can be kept permanent or deleted when the application is finished with it using standard DROP TABLE syntax.