SELECT and INSERT
Explore how to use SELECT and INSERT statements together to insert multiple rows from one table to another, create new tables with data in one step, and manage duplicate entries using the IGNORE clause. Understand techniques for copying table structures and data while maintaining keys.
We'll cover the following...
We'll cover the following...
SELECT and INSERT
MySQL provides us the facility to insert several rows from another table into an existing table using a combination of select and insert statements. In fact, we can also create a table on the fly and fill it up with rows from another table.
Syntax to Insert in an Existing Table
INSERT INTO table1 (col1, col2)
SELECT col3, col4
FROM table2;
Syntax to Insert in a New Table
CREATE TABLE newTable (col1 <datatype>, <col2>)
SELECT col3, col4
FROM table2;
Connect to the terminal below by clicking in the widget. Once ...