mysql select into
时间: 2023-10-25 09:33:22 浏览: 133
MYSQL SELECT INTO 和 INSERT INTO SELECT
MySQL SELECT INTO is used to create a new table and populate it with data from an existing table. The syntax for SELECT INTO is:
SELECT column1, column2, ...
INTO new_table_name
FROM existing_table_name
WHERE condition;
The new_table_name is the name of the new table that will be created, and existing_table_name is the name of the table that contains the data to be copied. The WHERE clause is optional and can be used to specify a condition that the data must meet to be included in the new table.
Example:
Let's say we have a table named "employees" with columns "id", "name", "age", and "salary". We want to create a new table named "young_employees" that contains only employees under the age of 30.
The SQL statement would be:
SELECT id, name, age, salary
INTO young_employees
FROM employees
WHERE age < 30;
This will create a new table named "young_employees" and populate it with data from the "employees" table where the age is less than 30. The new table will have the same columns as the original table.
阅读全文