7

Similar to this question : SQL Statement with multiple SETs and WHEREs

Is there a way to perform multiple sets, as shown below.

UPDATE  table
SET ID = 111111259
SET Name = "Bob"
SET Phone = 1111111261
WHERE ID = 2555

Thanks.

Community
  • 1
  • 1

3 Answers3

15

This is possible,

UPDATE table SET Name = 'aaa', Col2 = 'bbb' WHERE ID IN (2555, 2666)

What you are asking for is setting multiple values to same column and same row.

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
3

No need of SET for each column. do it like

UPDATE  table
SET ID = 111111259,
Name = 'Bob',
Phone = 1111111261
WHERE ID = 2555
Rahul
  • 76,197
  • 13
  • 71
  • 125
1

No. There is no way to do what your query suggests. You are trying to set the same column, ID, to three different values. What is sql supposed to do in this case? You can set multiple columns in the same update statement, but you can't set the same column to three different values.

To update multiple columns, use a comma.

UPDATE  table
SET ID = 111111259,
Name = 'Bob',
Phone = 1111111261
WHERE ID = 2555
Vulcronos
  • 3,428
  • 3
  • 16
  • 24