MySQL SQLLesson 41Free preview
MySQL INSERT SELECT
This lesson is part of MySQL · All levels
Summary
INSERT INTO ... SELECT allows us to directly copy data from the SELECT query results into other tables without having to write one by one. Suitable for filing, light migration, or filling out summary tables. The number and order of columns in the SELECT section must correspond to the list of destination columns.
Key points
- INSERT INTO the SELECT_target table... copy the query result line to the destination table
- The number of SELECT columns must be equal to and equal to the destination column
- Specify the list of columns explicitly to keep it secure when the table structure changes
- Can be accompanied by the WHERE clause to select a certain line only
- The clause on duplicate key update makes the operation upsert
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.