Problem:You would like to create a new table with data copied from another table. Example:Our database has a table named
In the database, let’s create a new table named It is important to note that we are creating a new table. The table The CREATE TABLE AS SELECT StructureTo create a new table from another table, you can use Solution 1:CREATE TABLE florist AS SELECT * FROM product WHERE category = ’flower’; Here is the result of the query:
Using The new table The SELECT INTO StructureAnother solution is to use Solution 2:SELECT id, name, price INTO florist FROM product WHERE category=’flower’; Here is the result:
Discussion:If you would like to create a new table based on the structure and data from another table, you can use the Notice that there are more columns in the table Next, use the keyword If you would like to select filtered rows from the table, use the In this example, we are creating a new table Of course, if you want to create a table using all of the columns in the other table, you can use Solution 2:SELECT * INTO florist FROM product WHERE category=’flower’; Here is the result:
Using |