S
S
StasianCheg2020-07-07 10:30:19
MySQL
StasianCheg, 2020-07-07 10:30:19

How to update a column of one table with a value from another?

I have two tables, table1 and table2. I need to update the fee column in table2 with the value of the komissiya column from table1, where the values ​​in the transaction table1 column are equal to transaction table2.

UPDATE table2
SET fee = (SELECT table1.komissiya FROM table1
WHERE table1.transaction = table2.transaction);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2020-07-07
@StasianCheg

UPDATE table2
  INNER JOIN table1 ON table1.transaction = table2.transaction
  SET table2.fee = table1.komissiya

N
Nikita Davydov, 2020-07-07
@nikitos42050

INSERT INTO `table1` SELECT * FROM `table2`;
This simple query will take data from table2 and insert it into table1

INSERT INTO `table1`(`row1`, `row2`, `row3`) SELECT `row1`, `row2`, `row3` FROM `table2`;

Here is such a simple solution for copying data from one MySQL table to another.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question