4

I want to update a password field from a given value that exists from another table.

user_info:

--------------------------------------------
| user_login | password |
|------------|-----------------------------|
| ad | 2ドルa12ドル$oGBdoD....ia9mk25OHu |
--------------------------------------------

user_contacts

-------------------------
| user_login | email |
|------------|----------|
| ad | [email protected]|
-------------------------

I would like to change the password by identifying the user_login using the associated email address. So, something like:

UPDATE user_info SET password = '2ドルa11ドル$fwea...IEI' WHERE user_contacts.email = '[email protected]';

Would anyone have an idea how to go about this? I've been trying to search for an answer online, but I've either not been able to find anything relating to this.

Cheers!

asked Jul 14, 2015 at 23:33

1 Answer 1

4

I believe this can be solved relatively quickly, by adding a FROM clause to your UPDATE, and adding an additional equality condition, namely, adding user_info.user_login = user_contacts.user_login.

UPDATE user_info SET password = '2ドルa11ドル$fwea...IEI' 
FROM user_contacts
WHERE user_info.user_login = user_contacts.user_login
AND user_contacts.email = '[email protected]';

This will almost certainly do what you are asking.

Refer to the PostgreSQL Documentation on UPDATE for more info.

answered Jul 14, 2015 at 23:51
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.