Artem
Artem

Reputation: 4639

Update column in row - column_1 = column_2

I added one column to my table with:

ALTER TABLE dn_car_repair_options ADD option_id INTEGER

Now this table has next DDL:

CREATE TABLE table_name (id INTEGER PRIMARY KEY, 
node_id INTEGER, 
name VARCHAR,
car_id INTEGER DEFAULT (0),
option_id INTEGER);

And I want UPDATE all rows where (row1)option_id = (row1)id

Can I make this using SQLite?

Upvotes: 1

Views: 22

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175596

After creating new column use simple UPDATE:

UPDATE dn_car_repair_options 
SET option_id = id;

Without WHERE clause it will affect all rows in table.

Upvotes: 2

Related Questions