N
N
Nikita Kamenev2021-07-25 12:43:18
MySQL
Nikita Kamenev, 2021-07-25 12:43:18

How to update records along with select from another table?

Admin table with three columns AdminID, username, password. Table Users with three of the same columns. How to make a query that would update the password in the Admin table with the password from the Users table, where UserID=123?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-07-25
@NickStone

MySQL:

UPDATE Admins A
JOIN Users U ON U.UserID = A.AdminID
SET A.password = U.password
WHERE U.UserID = 123;

Test MySQL here
MS SQL:
UPDATE Admins
SET Admins.password = U.password
FROM Admins A JOIN Users U ON U.UserID = A.AdminID
WHERE A.AdminID = 123;

MS SQL Fiddle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question