MySQL Phrasebook

# General syntax for INSERT ... SELECT INSERT table_one (list, of, columns) SELECT ...;

The INSERT command can be combined with a SELECT command to allow easy copying of rows from one table to another table.

The syntax is very simple. Take the front part of the INSERT command (up to the VALUES clause) and graft a SELECT command to it. Just make sure that the SELECT returns one column for every column that the INSERT command requires.

This example shows the general syntax for the INSERT ... SELECT command. For a more complex example that demonstrates a practical use of this feature, see phrase "Splitting a Column into Its Own Table" in Chapter 5, "Manipulating Data."

Категории