Mysql - fill / update a field with other fields based on another field condition that is true

I want to update all fields in a table based on another field with a condition that is true, e.g.

Table 1

field1 (string)

field2 (string)

field3 (condition for verification)

field4 (field for updating)

In table 1, if field3 = "XYZ", then I would like field 4 to be updated with a row consisting of field1 and field2.

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

Unfortunately, this will obviously replace all values ​​of field4 and does not do what I was looking for. I looked online to better show how I can do this, but no luck .. it's Greek to me .. any help or direction.

+4
source share
1 answer

If I do not understand you, you want to use the WHERE clause:

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

Here is information about him.

+8
source

Source: https://habr.com/ru/post/1495022/


All Articles