0

Let take a example, there are two tables as bellow.

OldData
-----------
    id
    name
    address

NewData
-----------
    nid
    name
    address

I want to update OldData table with NewData table.

For that purpose I am trying to use the following query:

UPDATE OldData SET (name, address) = (SELECT name, address FROM NewData WHERE nid = 234)
WHERE id = 123

But it gives a syntax error.

What is the proper way of doing what I try?

0

3 Answers 3

5
UPDATE OldData o, NewData n 
SET n.name = o.name, n.address = o.address 
where n.nid=234 and o.id=123;
Sign up to request clarification or add additional context in comments.

1 Comment

It should be SET o.name = n.name, o.address = n.address.
0

Try this:

Update oldData set name = (select name from newData where nid = 234),address = (select address from newData where nid = 123);

Comments

0

Try This :

UPDATE OldData a,NewData b 
SET a.name = b.name , a.address = b.address 
WHERE a.id=123 AND b.nid = 234

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.