How to create a temporary table and assign values in My…

In MySQL, you can create a temporary table and assign values using the following methods:

  1. Create a temporary table using the CREATE TABLE statement, and insert data into the temporary table using the INSERT INTO statement.
CREATE TEMPORARY TABLE temp_table (
    id INT,
    name VARCHAR(50)
);

INSERT INTO temp_table (id, name)
VALUES (1, 'John'), (2, 'Jane'), (3, 'Tom');
  1. Create a temporary table using the SELECT INTO statement, and insert data selected from other tables into the temporary table.
SELECT id, name
INTO temp_table
FROM original_table;

Please note that temporary tables will be automatically deleted after the current session ends. If you need to use temporary tables across multiple sessions, consider using persistent tables instead.

bannerAds