insert data from one table into another using a condition mysql

marcos j

hello I have the following problem I have two tables let's say these are table 1 and table 2. Table 1 has column A, B, C, D and table 2 has column A, B, C, D, E, F, G, H, I I need to insert data B, C, D from table 1 in table 2 in columns F, G, H using as Condition that A = A

I can not use

INSERT INTO table2 (F, G, H) SELECT B, C, D FROM table1;

since the data is out of order so when inserting the data they would be mixed

Is it possible to make a sentence that complies with the request, and if it complies, in what way would it be?

GMB

I need to insert data B, C, D from table 1 in table 2 in columns F, G, H using as Condition that A = A

I think you want update, not insert:

update table2 t2
inner join table1 t1 on t1.a = t2.a
set t2.f = t1.b, t2.g = t1.c, t2.h = t1.d

For each row in table2, this searches for a match in table1 with a match on a; when found, it updates columns f, g and h of table2 with values of column a, b, c of table1.

For this to work consistently, a should be a unique key in both tables.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

mysql :: insert into table, data from another table?

MySQL: insert values in new table from an old one using another mapping table

Copy and then insert data from one cell in a table to another cell in that table

How to insert rows from one table into another table in MYSQL

Retrieve data from one table and insert/update in another table in mysql

SQLite: How to retrieve data from column in one table using SELECT to insert retrieved data in another table

PSQL query to insert the records from one table to another based on condition

Transfer data from one table to another on insert

Moving data from one mysql table to another

Move data from one MySQL table to another

Procedure to insert a data from one table to another table after calculations

Insert data from a table to another one in MySQL with where condition

Insert Data From One Table to Another Table with default values

Insert data from one database to another in mysql

How to insert and retrive data from one table to another table in mysql database

MySQL add data from one table to another

MySQL - Insert table data from another table

MySQL insert into column data from another table

Insert Data From One Table to Another Table and Add New Values

Transferring data from one table to another using a where clause mysql

Insert Data From One Table To Another - MySQL

select data from one column based on another column's condition in the same table and insert that resulting data to another table

Laravel insert data from one table to another table error

BigQuery - Using INSERT INTO to copy data from one nested table into another nested table

Insert bulk of data from one table to another MySQL Python

find and extract data from one table and insert it into another in php and mysql

MySql: Insert data from one table to another

mysql copy data from one table to another using foreign key

how to insert data from one table to another table using type in plsql