Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you think you have some skills to help others

help someone and become a part of our community - List Q & A

MySql - insert data from one table to another

0 contributions
10 points

Using MySQL it is possible to insert data from one table to another in following way.

1. INSERT ... SELECT query example

This examples show how to copy data from `src_table` to `dst_table`.

1.1. Copping selected colums

Only selected columns are copied with created one value ('copied').

INSERT INTO `dst_table` (`name`, `status`, `source_id`) 
SELECT `name`, 'copied', `id` 
FROM `src_table`
ORDER BY `name` ASC 

1.2. Copping all columns

To use this approach both tables should have similar coumns.

INSERT INTO `dst_table` (SELECT * FROM `src_table`);

or

INSERT INTO `dst_table` (SELECT * FROM `src_database`.`src_table`);

Note: access to `src_database` is necessary.

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more