Geek Slack

My SQL Tutorial
    About Lesson


    MySQL INSERT INTO SELECT Statement


    MySQL INSERT INTO SELECT Statement

    The INSERT INTO SELECT statement in MySQL is used to insert data into a table from the result of a SELECT query. It allows you to quickly copy data from one table to another or insert computed or filtered data into a table.

    Example:

    INSERT INTO new_employees (employee_id, employee_name, department_id)
    SELECT employee_id, employee_name, department_id
    FROM temporary_employees
    WHERE joining_date > '2022-01-01';

    This query inserts data into the new_employees table from the temporary_employees table, including only employees who joined after January 1, 2022.

    The INSERT INTO SELECT statement is a powerful tool for copying, transforming, and filtering data between tables in MySQL.