Sql: insert subquery result to column

61 views Asked by At

I have a table with several columns. I want to create a new column from an existing one. Say column "A" is text, I want to insert into column "B" the left 10 characters of column "A".

I do:

insert into table (B) select left(A, 10) from table;

However, I want this to be aligned with column "A" not as new rows, how do I do that?

1

There are 1 answers

3
Sergey Kalinichenko On BEST ANSWER

I want this to be aligned with column "A" not as new rows

Insert adds new rows. Since you need to update existing ones, use UPDATE:

UPDATE MyTable
SET B = LEFT(A, 10)