Skip to content
Advertisement

Inserting a value in particular cell of DB2 blu table

I want to insert a value in a column “column_1” of table “table_1” with a condition where column “column_2” has a particular value and column “column_3” value is not like some value. “column_2” and “column_3” are both in the same table “table_1”.

I tried the following query but I am not getting require result.

INSERT INTO Table_1 (Column_1) VALUES ('Distribution') where column_2 = 'ABC' and column_3 not like '%123%'

Can anyone help me in writing proper query for this requirement.

Advertisement

Answer

I think you want update:

update table_1
    set column_1 = 'Distribution'
    where column_2 = 'ABC' and column_3 not like '%123%';

insert adds new rows to the table. update changes values in columns in existing rows.

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