Jimmy Servlet
Jimmy Servlet

Reputation: 155

SQL - how can I copy a column and its data to a new column in the same table?

I know i want to use an update statement but im having trouble with the structure of the query

Upvotes: 2

Views: 118

Answers (4)

srini.venigalla
srini.venigalla

Reputation: 5145

The first of the following 2 SQL statements will create the new column in the table, and the second, update statement will populate the new column from the old column.

alter table Table1 add newColumn char(32);
update table1 set newColumn=oldColumn;
commit;

Upvotes: 1

user98534
user98534

Reputation: 195

update table_name set column_to_be_changed = existing column 

Upvotes: 0

marcoo
marcoo

Reputation: 869

UPDATE table
SET column2 = column1

Upvotes: 1

Guffa
Guffa

Reputation: 700840

You can't create a new column using an update, you have to do that first. Then it's just as simple as:

update TheTable set NewColumn = OldColumn

Upvotes: 1

Related Questions