Ted
Ted

Reputation: 3875

Update with values in other column in a single query?

I have a table tbl_a, with "ID" as a primary key, with columnns "A1","B1","A2","B2"

I'd like to make an update query that updates ID as:

A1 = B1 and A2 = B2

so that if the table was

ID| A1| A2| B1| B2  
-------------------
7 | 0 | 0 | 5 | 3 

after the update:

ID| A1| A2| B1| B2
---------------
7 | 5 | 3 | 5 | 3 

Is that possible to do on one query?

Upvotes: 0

Views: 52

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 180927

Seems as simple as

UPDATE table1 SET A1=B1, A2=B2;

Naturally if you want to do it for only the row with ID=7 you can do

UPDATE table1 SET A1=B1, A2=B2 WHERE ID=7;

Demo here.

Upvotes: 3

Related Questions