SELECT and INSERT
This lesson discusses inserting data into a table using SELECT and INSERT in a single query.
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 connected, the command line prompt will show up. Enter or copy and paste the command ./DataJek/Lessons/35lesson.sh and wait for the MySQL prompt to start-up.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.