2

I have two tables as below:

  • abc:

    • id
    • icon
    • timestamp
  • xyz:

    • id
    • dob
    • abcId
    • icon
    • timestamp

i want to update a icon value in xyz table with specific id. For this i am using below query.

update xyz t set image = (select image from abc t1 where id = t.abcId);

But this update all the values. Can any one please update this.

2 Answers 2

2

You forgot to add a WHERE clause to the UPDATE statement, that's why all rows are updated.

Try adding the following at the end of the statement:

WHERE t.id = 42

Then only the xyz with id 42 will be updated.

Sign up to request clarification or add additional context in comments.

Comments

1

I suggest this query:

update xyz t 
set image = 
    (select image from abc t1 where t1.id = t.abcId) 
where t.id="**ID That You Want To Update**";

Comments

Your Answer

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.