Menu

Toshimaru's Blog

MySQL: Insert Result of Select query

Normal Insert

Use INSERT INTO ~ VALUES ~ for normal insert query.

INSERT INTO
  table_name(col1, col2, ...)
VALUES
  (val1, val2, ...)

Insert Result of Select query

Then, how can you insert result of select query?

You don’t need to add VALUES after INSERT INTO.

Just add SELECT after INSERT INTO.

INSERT INTO
  table_name(col1, col2, ...)
SELECT
  col1, col2, ...
  FROM another_table_name;

Reference

Load more