Skip to content
Advertisement

After Search in SQL Update a column value in the found rows

I have a DB table where a Field can have several different values, I want to update a field with certain values please see table below

ID  Name1   Place   Number
1   Key     TR       3
2   Lock    BG       45
3   Turn    GH       67
4   Key     KL       89

I would like to change the Name1 fields containing Key with Keys2. My actual table has more than 100 rows so I don’t want to just look for the ID and then replace it.

The search part is not a problem I can do that as follows:

Search * tableX where 'Name1' = 'Key'

So this would find the rows with ID 1 and 4. The I would like to update these found rows so the table now looks like

ID  Name1   Place   Number
1   Key2    TR      3
2   Lock    BG      45
3   Turn    GH      67
4   Key2    KL      89

I would not know where to start to update all of found rows. any help is welcome

Advertisement

Answer

So, you use update:

update t
    set Name1 = 'Key2'
    where Name1 = 'Key';

Is there something that I’m missing in your question?

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement