T
T
titronfan2016-05-26 21:11:46
MySQL
titronfan, 2016-05-26 21:11:46

How to update the data of one field in the table with one SQL query to another?

Hello! It is possible that the question is not well-defined.
In general, a MySQL database and one table: accounts .
Table structure (fields):

name             |   mail                 |   manager
Ivan Ivanov      |   [email protected]   |   Petr Petrov
Sidor Sidorov    |   [email protected]  |   Sergey Sergeev
Petr Petrov      |   [email protected]   |   Sidor Sidorov
...

How to make the record of the manager field updated with the mail value in the link (the manager field with the name field).
Should be in the output:
name             |   mail                 |   manager
Ivan Ivanov      |   [email protected]   |   [email protected]
Sidor Sidorov    |   [email protected]  |   [other value]
Petr Petrov      |   [email protected]   |   [email protected]
...

Thanks everyone for the advice!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
titronfan, 2016-05-26
@titronfan

Решение такое:

UPDATE accounts AS U1, accounts AS U2 SET U1.manager = U2.mail WHERE U2.name = U1.manager

Дмитрий Ковальский, 2016-05-26
@dmitryKovalskiy

На MS SQL можно примерно такой скриптик выполнить. на MySql не уверен.

UPDATE accounts 
SET manager = manager.mail
FROM accounts as A
INNER JOIN accounts as manager ON a.manager = manager.name

#
#algooptimize #bottize, 2016-05-26
@user004

update
set [manager] = [mail]
with update syntax

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question