Languages
[Edit]
EN

MySql - insert data from one table to another

10 points
Created by:
JustMike
26120

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.

Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join