6

I want to update all fields in a table based on another field having a condition being true, e.g.

Table1

field1 (string)

field2 (string)

field3 (condition to check)

field4 (field to update)

In table1, if field3 = "XYZ" then i would like field 4 to be updated with a string consisting of field1 & field2 ..

I've tried the following:
UPDATE table1 SET field4 = CONCAT(field1,field2)

Unfortunately this obviously replace all the field4 values and didn't do what I was looking for .. I've looked online for a better example of how I can accomplish this but no luck .. it's greek to me .. any help or direction is appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
calstatehomes
  • 63
  • 1
  • 4

1 Answers1

11

Unless I'm misunderstanding you, you want to use a WHERE clause:

UPDATE table1
SET field4 = CONCAT(field1,field2)
WHERE field3 = "XYZ"

Here is some information on it.

Tomcat
  • 606
  • 6
  • 18