'When column entry is "other' then replace with entry from another column

I hope someone can help (this is my first time posting!). Basically I want to do the following: when the entry in column a is 'other' replace with the entry in column b

I have tried numerous things with no success. This was most recent attempt:

select column_a, column_b from [data_table] update set column_a = column_b where column_a = 'other'

Any ideas?



Solution 1:[1]

It depends on whether you want to change the data in the database, or you just want the report to reflect the data you want.

Just for SELECT into a report:

SELECT 
  column_a
, CASE column_a
    WHEN 'other' THEN column_b
    ELSE column_a
  END AS column_a
, column_b
FROM data_table
;

To change the data in the database:

UPDATE data_table
SET column_a = column_b
WHERE column_a = 'other'

Solution 2:[2]

This should work,

And please include the errors, or issues in more detail.

select column_a, column_b from data_table
update data_table
set column_a = column_b
where column_a = 'other' ;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 marcothesane
Solution 2 Dhananjay Dahiya 2k19ae020