Click here to Skip to main content
15,922,407 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I want to write a update query by considering two table. In my case i want to change the password of a particular person by considering his email id. Means personPassword is one field in person table. And personEmail is another field in another table. My query is :

SQL
UPDATE Person
SET personPassword = @NewOrganizerPassword
Where personEmailID = @PersonEmailID


The two tables are :

1) Person :

PersonID
PersonPassword

2) Person_Email :

PersonID
PersonEmail

How to write the update query for updating the person password.

Thanks in advance......
Posted

Try this:
SQL
UPDATE Person
SET Password = @Password
FROM Person p
INNER JOIN Person_Mail
ON p.Personid = Person_Mail.Personid
WHERE PersonMailID = @PersonMailID


Have a look on similar thread:
SQL update query using joins[^]

And an article on Using A SQL JOIN In A SQL UPDATE Statement [^]
 
Share this answer
 
Comments
Maciej Los 22-Jun-12 3:41am    
Good answer, my 5!
Prasad_Kulkarni 22-Jun-12 3:43am    
Thanks Man :)
if you not have personid value than u can use this query.

SQL
UPDATE Person
SET personPassword = @NewOrganizerPassword
Where PersonID =(select  PersonID from Person_Email  where personEmailID=@personEmailID)
 
Share this answer
 
Comments
Maciej Los 22-Jun-12 3:42am    
Good answer, my 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900